AutoFitRow and IndentLevel

Hi!


I found some problem with 7.1.0.0 version for .Net.
The AutoFitRow method calculates incorrect RowHeight when a rows cells have non zero IndentLevel. I wrote this code to illustrate it:

Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[ 0 ];
int row = 0;
int column = 2;
Cells cells = worksheet.Cells;
cells.SetColumnWidthPixel( 2, 270 );
Cell cell = cells[ row, column ];
// when IndentLevel == 0 this text need 2 rows to display
// when IndentLevel == 3 this text need 3 rows to display
cell.PutValue( “11111111111111111111111111111 1 1 11111111111111111111111111111 1 1” );
Style style = cell.GetStyle();
style.IsTextWrapped = true;
style.IndentLevel = 3;
style.Font.Name = “Courier New”;
style.Font.Size = 8;
cell.SetStyle( style );

worksheet.AutoFitRow( row );
double incorrectHeight1 = worksheet.Cells.GetRowHeight( row );
// must be 33.75 but actually is 22.5
workbook.Save( “BookWithIncorrectHeight1.xlsx” );

worksheet.AutoFitRow( row, column, column );
double incorrectHeight2 = worksheet.Cells.GetRowHeight( row );
// must be 33.75 but actually is 22.5
workbook.Save( “BookWithIncorrectHeight2.xlsx” );

style = cell.GetStyle();
style.IndentLevel = 0;
cell.SetStyle( style );

worksheet.AutoFitRow( row );
double correctHeight1 = worksheet.Cells.GetRowHeight( row );
// must be 22.5 and actually is 22.5
workbook.Save( “BookWithCorrectHeight1.xlsx” );

worksheet.AutoFitRow( row, column, column );
double correctHeight2 = worksheet.Cells.GetRowHeight( row );
// must be 22.5 and actually is 22.5
workbook.Save( “BookWithCorrectHeight2.xlsx” );

Regards, Alex.

Hi,


Using your code, I can see only one issue regarding the generated “BookWithCorrectHeight2.xlsx” file, The row height should be 33.75 but it has 22.5, am i right? please confirm here. Mind you, I am using latest fix: Aspose.Cells for .NET v7.1.0.2

Here is the sample code (with updated comments):

Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[ 0 ];
int row = 0;
int column = 2;
Cells cells = worksheet.Cells;
cells.SetColumnWidthPixel( 2, 270 );
Cell cell = cells[ row, column ];
// when IndentLevel == 0 this text need 2 rows to display
// when IndentLevel == 3 this text need 3 rows to display
cell.PutValue( “11111111111111111111111111111 1 1 11111111111111111111111111111 1 1” );
Style style = cell.GetStyle();
style.IsTextWrapped = true;
style.IndentLevel = 3;
style.Font.Name = “Courier New”;
style.Font.Size = 8;
cell.SetStyle( style );

worksheet.AutoFitRow( row );
double correctHeight1 = worksheet.Cells.GetRowHeight( row );
// must be 22.5 and actually is 22.5
workbook.Save( “BookWithCorrectHeight1.xlsx” );

worksheet.AutoFitRow( row, column, column );
double correctHeight2 = worksheet.Cells.GetRowHeight( row );
// must be 33.75 but actually is 22.5
workbook.Save( “BookWithCorrectHeight2.xlsx” );

style = cell.GetStyle();
style.IndentLevel = 0;
cell.SetStyle( style );

worksheet.AutoFitRow( row );
double incorrectHeight1 = worksheet.Cells.GetRowHeight( row );
// must be 22.5 and actually is 22.5 – OK
workbook.Save( “BookWithIncorrectHeight1.xlsx” );

worksheet.AutoFitRow( row, column, column );
double incorrectHeight2 = worksheet.Cells.GetRowHeight( row );
// must be 22.5 and actually is 22.5 --OK
workbook.Save( “BookWithIncorrectHeight2.xlsx” );

Hi!


I’m sorry. I posted wrong sample (I try saved incorrect worksheets before correct worksheets and correct worksheets before incorrect worksheets, and I forgot check order of correct and incorrect worksheets in the sample).
Now the sample in head post is fixed.

First block:
worksheet.AutoFitRow( row );
double incorrectHeight1 = worksheet.Cells.GetRowHeight( row );
// must be 33.75 but actually is 22.5
workbook.Save( “BookWithIncorrectHeight1.xlsx” );
When I getting row height in the code, the result is wrong - 33.75. But the “BookWithIncorrectHeight1.xlsx” has been shown correctly in Excel. I think it is because Excel re-autofits this row when opening.

Second block
worksheet.AutoFitRow( row, column, column );
double incorrectHeight2 = worksheet.Cells.GetRowHeight( row );
// must be 33.75 but actually is 22.5
workbook.Save( “BookWithIncorrectHeight2.xlsx” );
Row height is wrong in the code and in the Excel.

Third and Forth blocks I add to check: “Is this problem linked on IndentLevel?”. And now I think that they are linked.

Thanks for fix, unfortunately the result did not change.

Regards, Alex.
Hi,

Thanks for explaining more.

I can find the issue as you mentioned now by using your updated code (in your first post in the thread). I can find the issue for "BookWithIncorrectHeight1.xlsx" and "BookWithIncorrectHeight2.xlsx" workbooks at runtime as you pointed out.

Sample code:

Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[ 0 ];
int row = 0;
int column = 2;
Cells cells = worksheet.Cells;
cells.SetColumnWidthPixel( 2, 270 );
Cell cell = cells[ row, column ];
// when IndentLevel == 0 this text need 2 rows to display
// when IndentLevel == 3 this text need 3 rows to display
cell.PutValue( "11111111111111111111111111111 1 1 11111111111111111111111111111 1 1" );
Style style = cell.GetStyle();
style.IsTextWrapped = true;
style.IndentLevel = 3;
style.Font.Name = "Courier New";
style.Font.Size = 8;
cell.SetStyle( style );

worksheet.AutoFitRow( row );
double incorrectHeight1 = worksheet.Cells.GetRowHeight( row );
// must be 33.75 but actually is 22.5
workbook.Save( "BookWithIncorrectHeight1.xlsx" );

worksheet.AutoFitRow( row, column, column );
double incorrectHeight2 = worksheet.Cells.GetRowHeight( row );
// must be 33.75 but actually is 22.5
workbook.Save( "BookWithIncorrectHeight2.xlsx" );

style = cell.GetStyle();
style.IndentLevel = 0;
cell.SetStyle( style );

worksheet.AutoFitRow( row );
double correctHeight1 = worksheet.Cells.GetRowHeight( row );
// must be 22.5 and actually is 22.5
workbook.Save( "BookWithCorrectHeight1.xlsx" );

worksheet.AutoFitRow( row, column, column );
double correctHeight2 = worksheet.Cells.GetRowHeight( row );
// must be 22.5 and actually is 22.5
workbook.Save( "BookWithCorrectHeight2.xlsx" );

I have logged a ticket with an id: CELLSNET-40340. We will soon look into it.

Thank you.

Hi,


After further evaluation of your issue, actually we do not support IndentLevel in the AutoFitRow currently because we could not get the width of indent level, in the unit of pixels.

After looking into this feature, we find the width of indent depends on standard font (e.g Tools->General-> Standard Font, in MS Excel 2003), but we still could not evaluate and do not know how the standard font works. Your issue is still open, if we have any update in near future, we will update you here immediately.


Thank you.

Hi,

Please download and try this fix: Aspose.Cells for .NET v7.1.0.5

Thank You!

It works perfectly!

Regards, Alex.

The issues you have found earlier (filed as CELLSNET-40340) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.