Problems - AutoFitColumns and Convert to Xlsx

Hi,

I have two problems.

1 - AutoFitColumns with Excel Expression is not work. The column with Excel Expression don't adjust.

2 - I have a Excel File (xls). I open this file and tried convert to xlsx. When I open xlsx, occurs the image below:

see the full project in the attachment.

Thank you.

Hi,

Thanks for your posting and using the Aspose.Cells.

Please download and try the latest version:
Aspose.Cells
for .NET v7.1.1.2

and let us know your feedback.

Hi,

Also, one issue with your code that I have seen is:
Please change your line of code for Workbook.Save() method, i.e.
workbook.Save(HttpContext.Current.Response, "teste.xlsx", ContentDisposition.Attachment, new XlsSaveOptions(SaveFormat.Xlsx));
to:
workbook.Save(HttpContext.Current.Response, "teste.xlsx", ContentDisposition.Attachment, new OoxmlSaveOptions());

Also check the topic:
http://docs.aspose.com/display/cellsnet/Saving+Files

Thank you.

Unfortunately, it did not work both situations.

Hi,

Error AutoFit:

Please see the following code. Please add the red line, it will work fine.

workbook.CalculateFormula();

C#


Workbook workbook = new Workbook();

Worksheet sheet = workbook.Worksheets[0];

Aspose.Cells.Style s = sheet.Cells[“B4”].GetStyle();

s.Custom = “#,###,###,###.00”;

sheet.Cells[“B1”].PutValue(1000);

sheet.Cells[“B1”].SetStyle(s);

sheet.Cells[“B2”].PutValue(2000);

sheet.Cells[“B2”].SetStyle(s);

sheet.Cells[“B3”].PutValue(1000);

sheet.Cells[“B3”].SetStyle(s);

sheet.Cells[“B4”].Formula = “B1B2B3”;

sheet.Cells[“B4”].SetStyle(s);

workbook.CalculateFormula();

sheet.AutoFitColumns();

workbook.Save(HttpContext.Current.Response, “teste.xls”, ContentDisposition.Attachment, new XlsSaveOptions(SaveFormat.Excel97To2003));

HttpContext.Current.Response.End();


Error Convert to Xlsx:

I was able to replicate the problem using the code below. I have attached the source and problematic output file.

C#

string filePath = @“F:\Shak-Data-RW\Downloads\Misc\test\TesteAspose\TesteAspose\example.xls”;


Workbook workbook = new Workbook(filePath);

workbook.Save(filePath + “.out.xlsx”);

We have logged this issue in our database. Once, we will fix it or have some update for you, we will let you know asap.

This issue has been logged as CELLSNET-40418

Hi,

There are some invalid merged cells in the xls file, please set
OoxmlSaveOptions.ValidateMergedAreas as true, then we will remove invalid
records, otherwise we will export all records of the merged cells in the xls
file.

Please try the following code:

C#


Workbook workbook = new Workbook(@“D:\Filetemp\example.xls”);

OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();

saveOptions.ValidateMergedAreas = true;

workbook.Save(@“D:\Filetemp\dest.xlsx”, saveOptions);

Hi,

It's working!

Thank you.