Detecting old Excel file formats

Hi,


I notice that the documentation says that FlexCel supports formats back to Excel 95.  Just for completeness, I want to have a trap to catch the rare instance of an older file (since there is no telling what the user may have), and thought I could do that with TExcelFileFormat.  But I see the only constants for that are v2003, v2007 and v2010.  Is there a simple way to detect versions earlier than FlexCel can handle? Or am I totally barking up the wrong tree?

Thanks.

Scott
Postage Saver Software

Hi,

TExcelFileFormat is used for defining in what Excel version you want to emulate when writing files. Currently FlexCel reads back to Excel 5 (Excel 5 and 95 used the same file format), but it can write only '97 or newer.  

While Excel 2003 and 2007 should write the same "xls" file format (Biff8), they are actually different, and they also have different signatures. So with TExcelFileFormat.v2003, you can make FlexCel say "this file was created with Excel 2003" when writing a file.

To know if FlexCel can open a file, you should just try to open and catch the Exception. For example:

function CanOpenFile(const filename: string): boolean;
begin
  Result := true;
  try
     xls.Open(filename);
  except on ex :EFlexCelXlsAdapterException do
      Result := false;
  end;
end;

If you want to do something different when the exception is because a non supported file format than when the error is other thing (like a file not found), you can check:
if ex.ErrorCode = TXlsErr.ErrFileIsNotSupported  then...
In the Except block.

In any case, you should't get much of those Exceptions. Since we support from Excel 5 up, an xls file that  raised the error should be in Excel 2, 3 or 4, which are windows 3.1 apps (Excel 4 is from 1992). Virtually the only way to get any of those files is from some third party app that creates them (And yes, there are some out there), but not from a real person using Excel 4.


Adrian Gallero2013-06-21 14:28:49

Great.  Thanks.