原創|其它|編輯:郝浩|2012-06-25 21:27:26.000|閱讀 4199 次
概述:有時候,在工作表的一個特定單元格中需要使用到明確換行或者文字環繞。例如,當單元格中有一個較大的文本時,你想在單元格中環繞文本或者插入多行文本以提高文本的可讀性,你可以使用Aspose.Cells.Style.setTextWrapped 方法。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
有時候,在工作表的一個特定單元格中需要使用到明確換行或者文字環繞。例如,當單元格中有一個較大的文本時,你想在單元格中環繞文本或者插入多行文本以提高文本的可讀性,你可以使用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");
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都控件網