aspose.cell 单元格内字体自适应列宽

2019-03-05 12:40发布

aspose.cell 有单元格缩小字体填充的设置吗,就相当于字体自适应列宽,就相当于excel的以下,只找到了单元格内自动换行的语句,

1条回答
ら.Afraid
2楼-- · 2019-03-05 13:30

https://docs.aspose.com/display/cellsnet/AutoFit%2BRows%2Band%2BColumns

缩小到适合
在字段中包装文本的选项是缩小文本大小以适合单元格的尺寸。 这是通过将Style对象的IsTextWrapped属性设置为true来完成的 。
介绍文档

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

// Create directory if it is not already present.
bool IsExists = System.IO.Directory.Exists(dataDir);
if (!IsExists)
System.IO.Directory.CreateDirectory(dataDir);

// Instantiating a Workbook object
Workbook workbook = new Workbook();

// Obtaining the reference of the worksheet
Worksheet worksheet = workbook.Worksheets[0];

// Accessing the "A1" cell from the worksheet
Aspose.Cells.Cell cell = worksheet.Cells["A1"];

// Adding some value to the "A1" cell
cell.PutValue("Visit Aspose!");

// Setting the horizontal alignment of the text in the "A1" cell
Style style = cell.GetStyle();

// Shrinking the text to fit according to the dimensions of the cell
style.ShrinkToFit = true;

cell.SetStyle(style);

// Saving the Excel file
workbook.Save(dataDir + "book1.out.xls", SaveFormat.Excel97To2003);


Examples-CSharp-Formatting-ConfiguringAlignmentSettings-ShrinkingToFit-1.cs hosted with ❤ by GitHub

查看更多
登录 后发表回答