Second call autoFitRows issue

Hi,


We have found issue with autoFitRows method. It does not work if we call twice:

public void testAutoFitRows() throws Exception {
Workbook wb = new Workbook();
Worksheet worksheet = wb.getWorksheets().get(0);
Cells cells = worksheet.getCells();
Row row = cells.getRows().get(0);

System.out.println("Initial size: " + row.getHeight());

// Set the width of first column
cells.setColumnWidth(0, 10);
// Set wrap text option
Style style = cells.get(0, 0).getStyle();
style.setTextWrapped(true);
cells.get(0, 0).setStyle(style);

System.out.println("After change cell format: " + row.getHeight());

// Apply auto-fit without data
AutoFitterOptions options = new AutoFitterOptions();
options.setOnlyAuto(true);
options.setAutoFitMergedCells(true);
options.setIgnoreHidden(true);
worksheet.autoFitRows(options);

System.out.println("After first call autoFitRows without data on sheet: " + row.getHeight());

cells.get(0, 0).putValue(“This is a autoFitRows second call issue”);

// Second call auto-fit
worksheet.autoFitRows(options);

System.out.println("After second call autoFitRows with data on sheet: " + row.getHeight());
}


Output looks as follows:
Initial size: 12.75
After change cell format: 12.75
After first call autoFitRows without data on sheet: 12.75
After second call autoFitRows with data on sheet: 12.75

Correct result looks as follows:
After second call autoFitRows with data on sheet: 51.0

Could you review and fix this issue?

Thanks.

Hi Anvar,


Thank you for contacting Aspose support.

We have evaluated your presented scenario our end while using the latest version of Aspose.Cells for Java 8.1.1.3. We have noticed that after inserting the data and calling Worksheet.autoFitRows for the second time, the wrap text operation does not seem to take effect, nor the row height is adjusted accordingly. However, if we comment out the first call of Worksheet.autoFitRows, the text is wrapped and row height is adjusted according to the data in cell.

We have logged this matter as an investigation in our bug tracking system. We will soon probe into this further to find a valid justification or a fix for this behavior. The ticket Id for your future reference is CELLSJAVA-40906. Please spare us little time for thorough analysis on our end. In the meanwhile, we will keep you posted with updates in this regard.

Hi again,


We have evaluated your presented scenario further. Please note. MS Excel does not auto fit the row heights if the cells are merged. Aspose.Cells provided this feature on customers’ request with AutoFitterOptions.AutoFitMergedCells property. If row height is not custom, MS Excel 97-2003 will auto fit the row height again when loading the file. In order to keep auto fitted result of the Aspose.Cells, we have to make the row height manual, that is the reason when AutoFitterOptions.OnlyAuto is true, the second call will ignore those rows.

Please comment the line options.setOnlyAuto(true); everything will work fine.

Java

Workbook wb = new Workbook();
Worksheet worksheet = wb.getWorksheets().get(0);
Cells cells = worksheet.getCells();
Row row = cells.getRows().get(0);
System.out.println("Initial size: " + row.getHeight());

// Set the width of first column
cells.setColumnWidth(0, 10);
// Set wrap text option
Style style = cells.get(0, 0).getStyle();
style.setTextWrapped(true);
cells.get(0, 0).setStyle(style);

System.out.println("After change cell format: " + row.getHeight());

// Apply auto-fit without data
AutoFitterOptions options = new AutoFitterOptions();
// options.setOnlyAuto(true);
options.setAutoFitMergedCells(true);
options.setIgnoreHidden(true);
worksheet.autoFitRows(options);

System.out.println("After first call autoFitRows without data on sheet: " + row.getHeight());
cells.get(0, 0).putValue(“This is a autoFitRows second call issue”);

// Second call auto-fit
worksheet.autoFitRows(options);

System.out.println("After second call autoFitRows with data on sheet: " + row.getHeight());

Hi,


Got it. Thanks for thorough explanation.

Thanks.