Row autoheight issue

Hi.


I have found some issue with autoheight row. For example - we have a cell with autoheight and word wrap. This cell contains some text. In next step we override cell’s value in large text block. Aspose.Cells not affected row height now

public void testRowHeight() {
try {
Workbook wb = new Workbook(“D:\test.xlsx”);
Cells cells = wb.getWorksheets().get(0).getCells();

Cell cell = cells.get(“C5”);

System.out.println(cells.getRowHeight(4));

cell.setValue(“Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam scelerisque scelerisque rhoncus. Proin sed venenatis ligula, quis interdum tellus. Phasellus suscipit quam ac elit feugiat ultricies. Donec ut purus mi. Suspendisse purus augue, sollicitudin id varius a, eleifend ac dui. Etiam scelerisque erat elit. Praesent tempus dui tristique, consequat dolor sit amet, pretium mauris. Nam posuere fringilla tortor, quis volutpat arcu facilisis eget. Maecenas eget cursus odio, vitae volutpat leo.”);

System.out.println(cells.getRowHeight(4));

wb.save(“D:\out.xlsx”);
} catch (Exception e) {
e.printStackTrace();
assertNull(e);
}
}

Best regards. Alexey

Hi Alexey,

Thanks for using Aspose.Cells.

We were able to observe this issue using the latest version with your given code. Aspose.Cells should adjust row height automatically or there should be some manual way of adjusting it. We have logged this issue in our database for investigation. We will look into it and fix this issue. Once, the issue is resolved or we have some other update for you, we will let you know asap.

This issue has been logged as CELLSJAVA-40772.

Hi,


Please add a line to your code, it would work fine.
e.g
Sample code:

//…
Cells cells = wb.getWorksheets().get(0).getCells();

Cell cell = cells.get(“C5”);

System.out.println(cells.getRowHeight(4));

cell.setValue(“Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam scelerisque scelerisque rhoncus. Proin sed venenatis ligula, quis interdum tellus. Phasellus suscipit quam ac elit feugiat ultricies. Donec ut purus mi. Suspendisse purus augue, sollicitudin id varius a, eleifend ac dui. Etiam scelerisque erat elit. Praesent tempus dui tristique, consequat dolor sit amet, pretium mauris. Nam posuere fringilla tortor, quis volutpat arcu facilisis eget. Maecenas eget cursus odio, vitae volutpat leo.”);

wb.getWorksheets().get(0).autoFitRow(4);
System.out.println(cells.getRowHeight(4));


Thank you.

Thanks, Amjad Sahi

Hi,


Good to know that it figures out your issue now. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.

Thank you.

We should apply autoheight selectively, but we have no information related to autoheight mode in row.


1. Open MS Excel and set wrap text option to all cells in row1
2. By default autoheight is working (setting large text block will increase height automatically)
3. Set wrap text option to all cells in another row2 and set heigth e.g. 60 for row2
4. Setting large text block in cells for this row will not increase height
5. To make row2 work in autoheight mode just apply it once: format->autofit row height
6. Any set in cells of this row will change height automatically

And so, to call autoFitRow properly we should have info - autoheigh mode applied to the row.

Could you clarify how to implemented this feature?

Hi Anvar,


Well, I am afraid, you got to manually call the Auto-fit rows/cols operation. I think you may try to use Worksheet.autoFitRows() to auto-fit all the rows at once.

Thank you.
Hi,

An user has developed in Excel 2010 the following template for post processing in a module:
1. set auto-fit mode for row1 (select the row1 entirely, apply format -> cell size -> AutoFit Row Height, apply format cells->aligment->wrap text)
2. set height 30 for row2 (select the row2 entirely , apply format->cell size->row height->30, apply format cells->aligment->wrap text)
3. save this template

Module load this template using Aspose.Cells and set text to the cells of row1 and row2. Aspose.Cells provide method to fit row height. However there is no API to get has the row fixed height or it has auto-fit mode applied. And so to call auto fit method for the row properly we should get the mode (fixed or auto-fit was initially set in template), and only for rows in auto-fit mode we should make call autoFitRow.

Does it make sense?

I have attached the template. Sample code:

@Test
public void testRowHeight() {
try {
Workbook wb = new Workbook("D:\\in.xlsx");
Cells cells = wb.getWorksheets().get(0).getCells();

Cell cell1 = cells.get(0, 1);
Cell cell2 = cells.get(1, 1);


System.out.println("Initial:");
System.out.println(cells.getRowHeight(0));
System.out.println(cells.getRowHeight(1));

cell1.setValue("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam scelerisque scelerisque rhoncus. Proin sed venenatis ligula, quis interdum tellus. Phasellus suscipit quam ac elit feugiat ultricies. Donec ut purus mi. Suspendisse purus augue, sollicitudin id varius a, eleifend ac dui. Etiam scelerisque erat elit. Praesent tempus dui tristique, consequat dolor sit amet, pretium mauris. Nam posuere fringilla tortor, quis volutpat arcu facilisis eget. Maecenas eget cursus odio, vitae volutpat leo.");
cell2.setValue("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam scelerisque scelerisque rhoncus. Proin sed venenatis ligula, quis interdum tellus. Phasellus suscipit quam ac elit feugiat ultricies. Donec ut purus mi. Suspendisse purus augue, sollicitudin id varius a, eleifend ac dui. Etiam scelerisque erat elit. Praesent tempus dui tristique, consequat dolor sit amet, pretium mauris. Nam posuere fringilla tortor, quis volutpat arcu facilisis eget. Maecenas eget cursus odio, vitae volutpat leo.");

// We don't have info what's rows should be processed by autoFitRow(?);

System.out.println("Final:");
System.out.println(cells.getRowHeight(0));
System.out.println(cells.getRowHeight(1));

wb.save("D:\\out.xlsx");
} catch (Exception e) {
e.printStackTrace();
}
}

Output:
Initial:
45.0
30.0
Final:
45.0
30.0

Open "out.xlsx" file in MS Excel: row1- 409.5, row2- 30.

Thanks.

Hi Anvar,

Thanks for your posting and using Aspose.Cells.

You can use the Worksheet.autoFitRows(boolean onlyAuto) method and pass it true as a parameter. It should fit your needs

Please see the following description of this method inside the Javadocs.

----------------------

autoFitRows


public void autoFitRows(boolean onlyAuto)
                throws java.lang.Exception
Autofits all rows in this worksheet.
Parameters:
onlyAuto - True,only autofits the row height when row height is not customed.

Hi,


Got it, thanks a lot. The documentaion states:

Another important thing to know is that AutoFit methods are time consuming methods. So, you should call these methods as less as possible to ensure your application’s efficiency.


Could you add autoFitRows(int row, boolean onlyAuto) to apply fitting for the specified row? We change just single cell and so suppose apply autofiit for the whole worksheet inefficient. This new method will eliminate performance degradation.

Thanks.

Hi,


Well, you may try to use the relevant autoFitRow() overloaded method (that has AutoFitterOptions as parameter), see the sample code below:
e.g
Sample code:

AutoFitterOptions options = new AutoFitterOptions();
options.setOnlyAuto(true);
worksheets.autoFitRow(row, firstcol, lastcol, options);


Method definition:

autoFitRow

public void autoFitRow(int rowIndex, int firstColumn, int lastColumn, AutoFitterOptions options)
throws java.lang.Exception
Autofits the row height.This method autofits a row based on content in a range of cells within the row.
Parameters:
rowIndex - Row index.
firstColumn - First column index.
lastColumn - Last column index.
options - The auto fitter options


Hope, this helps a bit.

Thank you.