Corrupted Excel-file opened by Flexcel

Hello
I have several 1000 Excel-Files, which are opened one after the other. One file seems to be corrupted, because Flexcel reports the index 1.048.577 is wrong. This number is 1 bigger than the possible max index for xlsx-Files.

How would it be possible to stop execution before the error occured?

Sincerely Peter

Hi,
You could try recovery mode and see if FlexCel can open it:
https://doc.tmssoftware.com/flexcel/vcl/api/FlexCel.Core/TExcelFile/RecoveryMode.html#texcelfilerecoverymode-property

Recovery mode isn't fool-proof and it might work or not depending on where the error is, but it might be worth a try.

Other idea would be to use virtual mode to read the file, and stop when you get to the error. You can see an example of how to read only the first 50 rows of a file here:
https://doc.tmssoftware.com/flexcel/vcl/samples/delphi/api/virtual-mode/index.html#working-in-virtual-mode-delphi

Instead of reading 50 rows, you could stop when there is an error.

Those are the 2 things I can think of, depending on the file and what you want to do with it, there might be other solutions. If you want, you can send me the file to adrian@tmssoftware.com and I can take a look.

Thanks for your answer.
I cannot send you the corrupted file, because I do not yet know which file is the culprit.

So a short procedure to test corruptness would be usefull.

Peter

Can't you just do:

for i :=1 to 1000 do 
begin
  try
    xls.Open(filename[i]);
  except
    on e:Exception do
    begin
       Log(filename[i] + ' cannot be opened');
     end;
end;