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

Free Support Forum - aspose.com

Sizing cells vertically for word-wrapped cells

I want to have a Notes column in a report that contains long text fields. This column needs to word-wrap. It also needs to autosize vertically to show all the text in each cell.

How do I do that in Aspose Cells for .NET?

Thanks

Steve

Hi,

May the following code help you for your need:

1).

Workbook wb = new Workbook();
Worksheet ws = wb.Worksheets["Sheet1"];
Cells cell = ws.Cells;
cell.SetColumnWidth(0, 16);
cell.SetRowHeight(0,28);
cell[0, 0].PutValue("Hi\nMy name is ...");
cell[0, 0].Style.IsTextWrapped = true;
cell[0, 0].Style.HorizontalAlignment = TextAlignmentType.Center;
ws.AutoFitRow(0);
ws.AutoFitColumn(0);
wb.Save("d:\\test\\wraping_text.xls", FileFormatType.Excel2003);

2).

Workbook oWB = new Workbook();
oWB.ChangePalette(Color.LightSkyBlue, 55);
Worksheet oSheet = oWB.Worksheets[0];
//Setting rows (1-10) heights accordingly.
for (int i = 0; i<10;i++)
{
oSheet.Cells.SetRowHeight(i, 30);
}
//Settting the first column width
oSheet.Cells.SetColumnWidth(0, 25);

Style oColumnNameStyle = oWB.Styles[oWB.Styles.Add()];
StyleFlag oColumnNameFlag = new StyleFlag();
oColumnNameFlag.FontName = true;
oColumnNameFlag.CellShading = true;
oColumnNameFlag.WrapText = true;

oColumnNameStyle.Font.Name = "Verdana";
oColumnNameStyle.ForegroundColor = Color.LightSkyBlue;
oColumnNameStyle.Pattern = BackgroundType.Solid;
oColumnNameStyle.IsTextWrapped = true;

Range oColumnNameRange = oSheet.Cells.CreateRange(0, 0,10,1);
oColumnNameRange.ApplyStyle(oColumnNameStyle, oColumnNameFlag);

oWB.Save("d:\\test\\wrappedcells.xls");

Thank you.

AutoFitRow is the function I was looking for.

Thanks.