We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Xlsx file corrupts when inserting ListObject

Hi there,

I am having problem inserting ListObjects to .xlsx versions of Excel.

Your sample code for ListObject insertion (from the API documentation) works fine when dealing with .xls files:

Workbook workbook = new Workbook(“C:\Test\Book1.xls”);
Aspose.Cells.Tables.ListObjectCollection lobs = workbook.Worksheets[0].ListObjects;
lobs.Add(1, 1, 11, 5, true);
workbook.Save(“C:\test\Book1Table.xls”);

However, when I switch the file version to xlsx it corrupts the file. But after auto-repairing the document, I can open it and see the inserted table.

I have tried opening the workbook with specific LoadOptions.Xlsx format and saving with SaveFormat.Xlsx format.

Here is my code:

LoadOptions loadOptions = new LoadOptions(LoadFormat.Xlsx);
Workbook workbook = new Workbook(“C:\Test\Book1.xlsx”, loadOptions);
Aspose.Cells.Tables.ListObjectCollection lobs = workbook.Worksheets[0].ListObjects;
lobs.Add(1, 1, 11, 5, true);
workbook.Save(“C:\Test\Book1Table.xlsx”, SaveFormat.Xlsx);

The sample file is a 2007 version blank empty spreadsheet (attached).

Does anyone know what I may be doing wrong?

Many Thanks,
Wubble U

Hi,


Please try the attached version v6.0.1.9, I have tested your code using your template File, it works fine with XLSX file too.

The output file is also attached.

Thank you.

Hi,

That’s great - I’ve tested with the new version and it is working fine now.
Thanks for your assistance.

Cheers,
Wubble U