Free Support Forum - aspose.com

AutoFitHeight not working

When I convert a file from FileFormatType.SpreadsheetML to FileFormatType.Excel97 using Aspose.Cells 4.0.1.0 the AutoFitHeight="1" row field seems to be ignored.

Opening the original XML file directly in Excel show the correct row sizing, but after conversion you can clearly see in the Dest.xls file that the sizing has been lost. I attached the sample Orig.xml file.

Sample code is below:

string origFileName = @"f:\tmp\Orig.xml";

string targetFileName = @"f:\tmp\Dest.xls";

License license = new License();

license.SetLicense("Aspose.Excel.lic");

Workbook workbook = new Workbook();

workbook.Open(origFileName, FileFormatType.SpreadsheetML);

workbook.Save(targetFileName, FileFormatType.Excel97);

How do you create such a spreadsheetML file? We cannot find a way to set AutoFitHeight field in Excel2003.

We ignore this field because there is no row height setting while AutoFitHeight = 1. You can try this workaround:

string origFileName = @"f:\tmp\Orig.xml";

string targetFileName = @"f:\tmp\Dest.xls";

License license = new License();

license.SetLicense("Aspose.Excel.lic");

Workbook workbook = new Workbook();

workbook.Open(origFileName, FileFormatType.SpreadsheetML);

workbook.Worksheets[0].AutoFitRow(1);

workbook.Save(targetFileName, FileFormatType.Excel97);

> How do you create such a spreadsheetML file?

I created the file I wanted in Excel 2003 and did a Save As XML Spreadsheet. Then I used that file as a template to generate similar files with more data using XSLT. I also manually edited the AutoFitHeight property.

> try this workaround

It works for this particular case. But the piece of code I pasted is generic. I want specific rows to be autofitted and only in some files. So, if this is the only solution you have, I will have to parse the input xml and check which rows need to be autofitted.

Thanks.

I checked your xml file. Since you manually edited the AutoFitHeight property, it's a little difference with normal SpreadsheetML routine.

In your file:

I changed it to:

And it works fine now. You can try this attached xml file.

Thanks. That worked even better.