Is there a way to tell how many rows IsTextWrapped has wrapped the text value onto after a cellstyle is applied?

Hi :slight_smile:

Is there a way to tell how many rows IsTextWrapped has wrapped the text value onto after a cellstyle is applied?

We use fixed width cells in a grid pattern, and the merge the appropriate number of cells when we write a value.

The text value in question can vary in length and I need to be able to apply wrapping and then query how many rows the value wrapped onto so I can merge the correct number of rows and add an appropriate border.

@mitnet,

Thanks for your query.

Well, although I am not entirely certain about your needs. But, I think as we do provide a method, i.e., Cell.GetWidthOfValue() which you may use to check the rough width needed by the cell value (it might not be accurate all the time), so you may use this method to detect the width for the cell in the column. You can compare the width with what you get with Cells.getColumnWidth() for the particular column. So, if it is greater/less than column’s width, you can think the text (in the cell) is overflown. And, here comes the wrapping text to place text in multiple lines.
e.g
Sample code:

Workbook workbook = new Workbook(path + "Book1.xlsx");
            Cell cell = workbook.Worksheets[0].Cells["A1"];
            int width = cell.GetWidthOfValue();
            int columnWidth = workbook.Worksheets[0].Cells.GetColumnWidthPixel(0);
            if (width > columnWidth)
            {
                Console.WriteLine("textOverflow");
               //Your code goes here.
               //...........
            }

You have to browse cells in the row to calculate/detect which cell’s data are overflown and you have to wrap text for those cells by applying the style to it.

Hope, this helps a bit.

Thanks for this :slight_smile:

I am getting somewhere using the GetWidthOfValue method along with the GetColumnWidthPixel method in order to calculate how many likely rows I am going to need in order to be able to display.

GetWidthOfValue / GetColumnWidthPixel / number of Columns available to be used.

but I am getting different values from GetWidthOfValue at different times. Why might it not be accurate all the time?

@mitnet,

Well, as we told you Cell.GetWidthOfValue() may give rough width needed by the cell value, the returned value might not be accurate all the time as it may involve font settings and other aspects.

Could you provide a test case (i.e., sample code (runnable)) with template file(s) to show the issue, we will check it soon.

Sure, I will need a some time to put it together as I am a bit busy so I will post it when I can. Thank you :slight_smile:

@mitnet,

Please take your time to prepare the sample and post us to reproduce the issue.