aspose 换行写_Aspose.Cells电子表格组件使用技巧(四):换行符和文字环绕

有时候,在工作表的一个特定单元格中需要使用到明确换行或者文字环绕。例如,当单元格中有一个较大的文本时,你想在单元格中环绕文本或者插入多行文本以提高文本的可读性,你可以使用Aspose.Cells.Style.setTextWrapped 方法。

参考下面的示例代码,实现单元格文字环绕或者换行:

单元格中文字环绕:

[Java]

//Create Workbook Object

Workbook wb = new Workbook();

//Open first Worksheet in the workbook

Worksheet ws = wb.getWorksheets().get(0);

//Get Worksheet Cells Collection

Cells cell = ws.getCells();

//Increase the width of First Column Width

cell.setColumnWidth(0, 35);

//Increase the height of first row

cell.setRowHeight(0, 65);

//Add Text to the First Cell

cell.getCell(0, 0).setValue("I am using the latest version of Aspose.Cells to test this functionality");

//Get Cell's Style

Style style = cell.getCell(0, 0).getStyle();

//Set Text Wrap property to true

style.setTextWrapped(true);

//Set Cell's Style

cell.getCell(0, 0).setStyle(style);

//Save Excel File

wb.save("C:\\WrappingText.xls");

使用明确的换行符:

你可以使用Java中的'\ n'插入到单元格中作为你的换行符。

[Java]

//Create Workbook Object

Workbook wb = new Workbook();

//Open first Worksheet in the workbook

Worksheet ws = wb.getWorksheets().get(0);

//Get Worksheet Cells Collection

Cells cell = ws.getCells();

//Increase the width of First Column Width

cell.setColumnWidth(0, 35);

//Increase the height of first row

cell.setRowHeight(0, 65);

// Add Text to the Firts Cell with Explicit Line Breaks

cell.getCell(0, 0).setValue("I am using \nthe latest version of \nAspose.Cells \nto test this functionality");

//Get Cell's Style

Style style = cell.getCell(0, 0).getStyle();

//Set Text Wrap property to true

style.setTextWrapped(true);

//Set Cell's Style

cell.getCell(0, 0).setStyle(style);

//Save Excel File

wb.save("C:\\WrappingText.xls");

(慧都控件网版权所有,转载请注明出处,否则追究法律责任)

标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,尊重他人劳动成果

文章转载自:慧都控件网

0

好文不易,鼓励一下吧!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值