Free Support Forum - aspose.com

Wrap text problem

Hello,

In the report, I need to wrap text in a header row - row 0.

This is my cope sample:

oSheet.Cells.SetRowHeight(0, 25)
oSheet.Cells.SetColumnWidth(3, 5)
oSheet.Cells.SetColumnWidth(7, 5)
oSheet.Cells.SetColumnWidth(9, 5)

Dim oColumnNameStyle As Style = oWB.Styles(oWB.Styles.Add())
Dim oColumnNameFlag As StyleFlag = New StyleFlag()
oColumnNameFlag.Borders = True
oColumnNameFlag.FontBold = True
oColumnNameFlag.HorizontalAlignment = True
oColumnNameFlag.CellShading = True
oColumnNameStyle.Font.IsBold = True
oColumnNameStyle.ForegroundColor = Color.LightSkyBlue
oColumnNameStyle.Pattern = BackgroundType.Solid
oColumnNameStyle.HorizontalAlignment = TextAlignmentType.Center
oColumnNameStyle.Borders(BorderType.BottomBorder).Color = Color.Black
oColumnNameStyle.Borders(BorderType.BottomBorder).LineStyle = CellBorderType.Thin
oColumnNameStyle.Borders(BorderType.TopBorder).Color = Color.Black
oColumnNameStyle.Borders(BorderType.TopBorder).LineStyle = CellBorderType.Thin
oColumnNameStyle.IsTextWrapped = True
Dim oColumnNameRange As Range = oSheet.Cells.CreateRange(0, 0, 1, 10)
oColumnNameRange.ApplyStyle(oColumnNameStyle, oColumnNameFlag)

oWB.Save(strReportNameAndPath, FileFormatType.Excel2000)

When I open Excel file, in the range cells property 'Wrap text' is unchecked.
What I am doing wrong?
Please help.

Hi,

Well, I think you missed a few lines, the complete code should be as follows:

.
.
'Since the LightSkyBlue color is not present on the standard color palette, so you should add to the palette first.

oWB.ChangePalette(Color.LightSkyBlue, 55)
.
.
oSheet.Cells.SetRowHeight(0, 25)
oSheet.Cells.SetColumnWidth(3, 5)
oSheet.Cells.SetColumnWidth(7, 5)
oSheet.Cells.SetColumnWidth(9, 5)

Dim oColumnNameStyle As Style = oWB.Styles(oWB.Styles.Add())
Dim oColumnNameFlag As StyleFlag = New StyleFlag()
oColumnNameFlag.Borders = True
oColumnNameFlag.FontBold = True
oColumnNameFlag.HorizontalAlignment = True
oColumnNameFlag.CellShading = True
oColumnNameFlag.WrapText = True
oColumnNameStyle.Font.IsBold = True
oColumnNameStyle.ForegroundColor = Color.LightSkyBlue
oColumnNameStyle.Pattern = BackgroundType.Solid
oColumnNameStyle.HorizontalAlignment = TextAlignmentType.Center
oColumnNameStyle.Borders(BorderType.BottomBorder).Color = Color.Black
oColumnNameStyle.Borders(BorderType.BottomBorder).LineStyle = CellBorderType.Thin
oColumnNameStyle.Borders(BorderType.TopBorder).Color = Color.Black
oColumnNameStyle.Borders(BorderType.TopBorder).LineStyle = CellBorderType.Thin
oColumnNameStyle.IsTextWrapped = True
Dim oColumnNameRange As Range = oSheet.Cells.CreateRange(0, 0, 1, 10)
oColumnNameRange.ApplyStyle(oColumnNameStyle, oColumnNameFlag)

oWB.Save(strReportNameAndPath, FileFormatType.Excel2000)

Thank you.

Thanks a lot.

I missed line: oColumnNameFlag.WrapText = True