有时候,在工作表的一个特定单元格中需要使用到明确换行或者文字环绕。例如,当单元格中有一个较大的文本时,你想在单元格中环绕文本或者插入多行文本以提高文本的可读性,你可以使用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
好文不易,鼓励一下吧!