Unexpected character "=" at pos 2 on formula: "==$D2="Contr ler sur le terrain"".

Hi there

I just downloaded and installed the newest version of Flexcel for VCL
hoping this error would be fixed since we last got a version. Sadly it is not.

To reproduce the error simply open the XLSX file with ApiMateRadStudio.exe.

Or do this
wb := TXlsFile.Create;
wb.Open('D:\Cantonnement 314.xlsx');

Localhost_KtBern-EFlexCelCoreException.txt (25.6 KB)

Cantonnement 314.xlsx (18.3 KB)

Is there a way to prevent the error or is there a bug fix on your side needed?

Thank you very much

Ricardo

Hi,
Sadly the problem is with the file, FlexCel is correctly reporting an error here.
You can verify this just by opening the file in Excel and saving it: After this ApiMate will load it properly.

This file looks like it is being done by a third party (openpyxl?). If you have control over the file, the best would be to generate it correctly. The problem with the file is in the conditional formatting: When saved to the file, they are saved as:

<formula>=$D2=&quot;Contrôler sur le terrain&quot;</formula>

And they should be saved as

<formula>$D2=&quot;Contrôler sur le terrain&quot;</formula>

(This is what Excel saves if you open and save the file, and then it is read correctly)

As said, if you have control over the file, make sure you don't add a "=" when setting the conditional format rules. Excel today isn't complaining and silently fixing it, but you never know if a newer update from Excel will stop reading those files.

Excel has been moving for a while to be less permissive with wrong files and report errors in files that it ignored before. Decades ago, Excel would shallow almost anything you wrote into the file, and ignore it or corrupt the data or even the internal memory. With the years, Microsoft has been tightening the security, and refusing to open a lot of files that it could before.

FlexCel has walked the opposite path: We started from the beginning being very strict about only allowing correct stuff to load instead of guessing what it could be and try to silently fix it. If a file is wrong, we just refuse to load it and do not do guess work about what it might have meant. But during the years we did get a lot of complains about "a file that Excel can read and FlexCel can't", like in this case, so we have been removing restrictions when the fix isn't a guess. (We also have a "recovery mode" that allows more dangerous fixings, but it won't cover this particular case, I just tried it) If you go to What's new in FlexCel Studio for VCL and FireMonkey | FlexCel Studio for VCL and FireMonkey documentation and search for "third", I've counted 25 entries of removing some restriction so an invalid file would load.

In this case, I am not sure. As said, the file is wrong so FlexCel is right to complain. (and let you know, so you can fix it). On the other hand, I can fully understand that you just might want to read a file you have no control of, and the error isn't helping.
So I am not decided yet if to put the fix to load this file in the "normal" open, or require a xls.RecoveryMode := true before opening it, as an acknowledge that you know the file is wrong and you don't care.

In any case, we will be adding a fix for this in our next release, which should be coming about a week from now. (don't quote me on exact dates, I hope it will be in a week, but I tend to underestimate the times...)

Just to let you know that we have already added a fix, that will just ignore the invalid extra "=" and not require RecoveryMode.
Next release will include the fix

Thank you very much for your comprehensive answer. Interesting stuff.
I don't know yet where the file is coming from. But I'll investigate.

And to the fix: Great! Thanks so much. So I'm just looking forward to the next release :slight_smile:

7.27 was released and it includes the fix.

Thank you. I'll check it out.