首页 新闻 会员 周边 捐助

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

0
悬赏园豆:5 [已解决问题] 解决于 2019-03-05 13:45

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

总编不过你的主页 总编不过你 | 初学一级 | 园豆:2
提问于:2019-02-25 15:10
< >
分享
最佳答案
0

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

收获园豆:5
家秋 | 菜鸟二级 |园豆:475 | 2019-02-27 11:35
其他回答(1)
0

自动换行和缩小字体来适应列宽是2个不同的概念吧,缩小字体来适应列宽可以用Spire.XLS (Excel类库)来实现

http://www.e-iceblue.cn/Introduce/Free-Spire-XLS-NET.html

//加载Excel文档
Workbook workbook = new Workbook();
workbook.LoadFromFile("Input.xlsx");

//获取第一张工作表
Worksheet sheet = workbook.Worksheets[0];

//指定需要自动缩小字体的单元格范围
CellRange cell = sheet.Range["A1:E3"];

//设置ShrinkToFit为true来缩小字体
CellStyle style = cell.Style;
style.ShrinkToFit = true;

//保存文档
workbook.Save();
KeepLearning_88 | 园豆:231 (菜鸟二级) | 2019-03-12 15:06
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册