We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Formatting a worksheet with Wrap Text property

Hi,

I am using Aspose.Cells in a excel report. Some of the columns are overflowing with Text and I am looking to implement the WrapText property of excel. Using the AutoFitColumn method did not help as it increases the column width to fit the longest text and thus makes the sheet not very user friendly. Can you please suggest me a way to wrap the text with the columns with fixed widths.

Thanks

Hemangajit

Hi Hemangajit,

Using style.IsTextWrapped = true; will wrap the text in to the cell.

Code snippet:

Workbook workbook = new Workbook();
workbook.Worksheets.Clear();
int i = workbook.Worksheets.Add();
Worksheet worksheet = workbook.Worksheets[i];
Aspose.Cells.Cell cell = worksheet.Cells["A1"];
cell.PutValue("Visit Aspose!");
Style style = cell.GetStyle();
style.IsTextWrapped = true;
cell.SetStyle(style);
workbook.Save("C:\\book1.xls", FileFormatType.Excel97To2003);

Thanks,

Hi Salman,
Thanks. It worked. But one thing is that, we have to set the style at cell level. so if I have to traverse through the entire sheet cell by cell and set the style. Is there any way we can set it at the sheet level or row or column level.

Thanks
Hemangajit

Hi Hemangajit,

We have logged the feature as suggested by you in our Issue Tracking System as 19205.

We will look into the possibility of this feature. This thread has been linked with this issue so that you can be further updated.

Kind Regards

Hi,

Please see the following sample code on how to format a complete row. You can also use Cells.ApplyColumnStyle() method to format a complete column.

Sample code:
Workbook workbook = new Workbook();
workbook.Worksheets.Clear();
int i = workbook.Worksheets.Add();
Worksheet worksheet = workbook.Worksheets[i];
Style style = workbook.Styles[workbook.Styles.Add()];
style.IsTextWrapped = true;
StyleFlag flag = new StyleFlag();
flag.WrapText = true;
//Apply style to the whole first row cells.
worksheet.Cells.ApplyRowStyle(0,style,flag);
workbook.Save(“e:\test\rowsformattingbook1.xls”);

Please see the document to know more about how to format rows or columns in a worksheet:
http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/formatting-rows-columns.html

Thank you.