Lazarus

Programming => Packages and Libraries => FPSpreadsheet => Topic started by: kjteng on August 11, 2020, 06:06:14 pm

Title: Problem with xlsx file
Post by: kjteng on August 11, 2020, 06:06:14 pm
If I repeatedly open certain worksheet (xlsx) for two times, any xlsx file subsequently saved (in the same apps) would not be readable by Excell (unless I let Excel to recover/repair it). Example codes:

Quote
       wbSource1.Workbook.ReadFromFile('test.xlsx');
       wbSource1.Workbook.Clear;
       wbSource1.Workbook.ReadFromFile('test.xlsx');
       wbSource1.SaveToSpreadsheetFile('test1.xlsx');

//   files attached:  test.xlsx can be opened in Excel.  test1.xlsx need to be
//   repaired before Excel open it.
After few hours of testing, I found that::-
I) within test.xlsx there is a file called custom.xml which contains some custom properties. These properties are duplicated twice (eg. 4 items would became 8 items) in test1.xls. Hence test1.xlsx cannot be read by Excel (Libreoffice  has no issue with test1.xlsx - I guess Libreoffice would ignore/automatically remove duplicate properties).
II) I can manually delete custom.xml and solve the above issue i.e. by opening the excel file (as archive) using 7zip.
 
My questions:
How can I prevent the above issue?
How do I remove the duplicate properties (or remove all this unwanted properties) programatically in fpSpread ?
.
Title: Re: Problem with xlsx file
Post by: wp on August 11, 2020, 06:31:17 pm
Ah... Workbook.Clear did not clear the metadata. Should be fixed now.

In order to restore readability of the damaged files you must fix them manually:
Title: Re: Problem with xlsx file
Post by: kjteng on August 12, 2020, 12:15:04 am
Thank you master for the detailed explanation. I will download the fix and try it.
Title: Re: Problem with xlsx file
Post by: kjteng on August 12, 2020, 03:33:14 am
Downloaded r7599. Problem solved. Tqvm.
TinyPortal © 2005-2018