IsTextWrapped doesn't work if the cell is merged

Dear Aspose,

The property style.IsTextWrapped doesn’t work if the cell is merged later. Are there any solution to this?

This is an example of the code in VB.Net

Dim value as String = “line 1”& vbCrLf & “line 2”
sheet.Cells(0, 0).PutValue(value)
Dim style As Aspose.Cells.Style = sheet.Cells(0, 0).GetStyle
style.IsTextWrapped = True
sheet.Cells(0, 0).SetStyle(style, True)
sheet.Cells.Merge(0, 0, 1, 2)

vbCrLf is a new line, if I don’t merge the cell the text will be in two lines, but if I merge the cell the text will be only in one line unless I double click the cell the text will display in two lines.

Thanks

@rltejada

Thanks for using Aspose APIs.

Please download and use the latest version and it should fix your issue.

We have tested your code with the latest version and it worked fine.

VB.NET

Dim wb As New Workbook

Dim sheet = wb.Worksheets(0)

Dim value As String = “line 1” & vbCrLf & “line 2”
sheet.Cells(0, 0).PutValue(value)
Dim style As Aspose.Cells.Style = sheet.Cells(0, 0).GetStyle
style.IsTextWrapped = True
sheet.Cells(0, 0).SetStyle(style, True)
sheet.Cells.Merge(0, 0, 1, 2)

sheet.Cells.SetRowHeight(0, 30)

wb.Save(“f:/download/output.xlsx”)

Here is the output Excel file generated with the given code for your reference.

output.xlsx.zip (Please remove .zip after downloading it) (6.7 KB)

Hi,

That works now. But now there are other problem, I need to use sheet.AutoFitRow(0) instead of sheet.Cells.SetRowHeight(0, 30) to auto fit the row because I don’t know how long the text will be or how many lines will have, “line 1” & vbCrLf & “line 2” was just an example. And in this case when the cell is merged sheet.AutoFitRow(0) doesn’t work, are there a solution to this?

Thank you for your help

@rltejada,

Well, you may try to instantiate AutoFitterOptions and specify the relevant attribute on. Now auto-fit row(s) with respect to auto-fitter options to cope with your issue. See the following lines of code that you should use instead:
e.g
Sample code:

............
  'sheet.Cells.SetRowHeight(0, 30)
        Dim options As New AutoFitterOptions
        options.AutoFitMergedCells = True
        sheet.AutoFitRow(0, 0, 0, options)
...........

Hope, this helps a bit.

Thank you.