Wrong height of wrapped cells

Aspose cells version 8.0.0

I found the problem, I can’t calculate height of rows with cells with long texts.
See example and attachment 1404134057124.xlsx.

public static void main(String[] args) throws Exception {
Workbook workbook = new Workbook( );
Cells cells = workbook.getWorksheets().get(0).getCells();
for (int i=1; i<10; i++) {
Cell cell = cells.get( “A” + i );
Style style = cell.getStyle();
style.setTextWrapped( true );
cell.setStyle( style );
cell.setValue( randomString( 5 * i ) );
cells.get(“B” + i).setValue( cells.getRowHeight( i - 1 ) );
}
String fileName = “C:\temp\” + System.currentTimeMillis() + “.xlsx”;
workbook.save( fileName );
System.out.println( fileName + " is created" );
}

public static String randomString( int len ) {

StringBuilder result = new StringBuilder();
for (int i = 0; i < len; ++i) {
char ch = (char) (‘a’ + (char) (Math.random() * 26));
result.append(ch);
}
return result.toString();
}

Hi,


Well, you need to call auto-fit rows function before reading the row heights, you may add a line to your code segment:
e.g
Sample code:

public static void main(String[] args) throws Exception {
Workbook workbook = new Workbook( );
Cells cells = workbook.getWorksheets().get(0).getCells();
for (int i=1; i<10; i++) {
Cell cell = cells.get( “A” + i );
Style style = cell.getStyle();
style.setTextWrapped( true );
cell.setStyle( style );
cell.setValue( randomString( 5 * i ) );

workbook.getWorksheets().get(0).autoFitRows();
cells.get(“B” + i).setValue( cells.getRowHeight( i - 1 ) );
}
String fileName = “C:\temp\” + System.currentTimeMillis() + “.xlsx”;
workbook.save( fileName );
System.out.println( fileName + " is created" );
}

public static String randomString( int len ) {

StringBuilder result = new StringBuilder();
for (int i = 0; i < len; ++i) {
char ch = (char) (‘a’ + (char) (Math.random() * 26));
result.append(ch);
}
return result.toString();
}

Thank you.



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.