Excel file does not open

I'm using following test procedure to open an Excel file. Some files does open, some files shows "The file "" is invalid.
Both are created with excel, maybe different computers and different Excel.
What I'm doing wrong?

unit test;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, AdvUtil, Vcl.StdCtrls, tmsAdvGridExcel,
  Vcl.Grids, AdvObj, BaseGrid, AdvGrid;

type
  TForm9 = class(TForm)
    AdvStringGrid1: TAdvStringGrid;
    AdvGridExcelIO1: TAdvGridExcelIO;
    OpenDialog1: TOpenDialog;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form9: TForm9;

implementation

{$R *.dfm}

procedure TForm9.Button1Click(Sender: TObject);
begin
  if OpenDialog1.Execute then begin
    AdvGridExcelIO1.XLSImport(OpenDialog1.FileName);
  end;
end;

end.

Hi,

Could it be that those are older versions of xls?  AdvGridExcelIO uses a cut-down FlexCel 3 engine under the hood, and FlexCel 3 only understands Excel 97 or newer xls files.

On the other hand AdvGridExcelImport ( https://www.tmssoftware.com/site/advgridfilters.asp )uses FlexCel 6 so if can open Excel 2 xls up to the latest, as well as xlsx.

But I am not sure if the problem is that the file is not xls 97 or if there is something else. If you can send me an example of the files that AdvGridExcelIO cannot open to adrian@tmssoftware.com I can give you more information.

As far as I know, both FlexCel 3 and FlexCel 6 can open any xls file they support, I haven't seen a file that is correct and that they cannot open (by correct I mean not corrupt, in the correct format, and not created by a different tool than Excel which didn't follow the xls/x documented format). And I see tens of xls files from different customers each month. 

But of course, that doesn't mean that there can be a case where we can't open a file, so if you can forward me some files you are having trouble with I can investigate this case more in depth.

Hi I got the file, thanks.

Sadly it is an Excel 95 file, which FlexCel 3 (And so AdvGridExcelIO) can't open. 

You can see it if you do a File->Save As in Excel:



On the other hand, I tried it with FlexCel 6 (And AdvGridExcelImport) and FlexCel 6/AdvGridExcelImport can open the file fine.

Thank you for test. I will save at least Excel97 next time.
Confusing is only, that message

"The file "" is invalid

shows no file name.

I think (but I am not 100% sure) that the filename "" is because we are using TStreams instead of loading directly from a filename. When loading from a stream, FlexCel doesn't know the filename, and there might be in fact no filename at all (if for example you were loading from a TMemoryStream).


In FlexCel 6 there are some extra guesses to get the filename when loading from a stream (so we test if the TStream is a TFileStream for example), but at the end, it is not always possible to know the filename as there might be no filename at all if you are loading the file from memory or a database.

Sorry, this topic is few years old, but I still have problems to open XLSX files.
Ist extension "XSLX" supported or not?
I can send you a short example.

Have a nice weekend.

Hi,
Yes, of course, xlsx has been supported since about 2012 with FlexCel 5. (it was already supported when this topic was created). We also support Excel95, 2, 3, and 4.

If you are having trouble with a specific file, you can send me the file to adrian@tmssoftware.com and I can take a look.

Just looking at the rest of the topic, is this about TAdvGridExcelIO? If that is the case, then no, AdvExcelIO doesn't support xlsx. FlexCel on the other hand does, and if you have a FlexCel license, you can use the free VCL Bridges ( TMS VCL Grid Excel Bridge Import/Export Bridge for TMS Grids to Excel .XLS and .XLSX files ) to work with xlsx files (and xls 2 to 97 too). The bridges are a more advanced version of TAdvGridExcelIO, with xlsx support among other stuff.

Hello Adrian,

thanks for info.
I have changed TAdvGridExcelIO to TAdvGridExcelImport/Export an it works now.