Recent

Author Topic: [SOLVED] Read Excel file with fpspreadsheet.  (Read 527 times)

Hansvb

  • Hero Member
  • *****
  • Posts: 754
[SOLVED] Read Excel file with fpspreadsheet.
« on: February 09, 2025, 08:08:05 pm »
Hi,

 I am trying to open an Excel file using FPspreadsheet. I get an error message with the readfromfile line. Besides "sfOOXML" I have tried other Excel formats and also sfOpenDocument, but I get the same error message everywhere. Error message: Tried to read a spreadsheet using an unsupported format.  FPspreadsheet version 1.16, just retrieved using the online package manager. I don't know if it makes a difference but I see fpspreadsheet in the Package Links that the state is invalid. That seems strange since I just added the package.

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls,
  9.   fpspreadsheet, fpstypes;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     Button1: TButton;
  17.     procedure Button1Click(Sender: TObject);
  18.   private
  19.  
  20.   public
  21.  
  22.   end;
  23.  
  24. var
  25.   Form1: TForm1;
  26.  
  27. implementation
  28.  
  29. {$R *.lfm}
  30.  
  31. { TForm1 }
  32.  
  33. procedure TForm1.Button1Click(Sender: TObject);
  34. var
  35.   openDlg: TOpenDialog;
  36.   workbook: TsWorkbook;
  37. begin
  38.   openDlg:= TOpenDialog.Create(Self);
  39.   workbook := TsWorkbook.Create;
  40.  
  41.   try
  42.     if openDlg.Execute then begin
  43.       workbook.ReadFromFile(openDlg.FileName, sfOOXML);
  44.     end;
  45.   finally
  46.     openDlg.free;
  47.     workbook.Free;
  48.   end;
  49.  
  50. end;
  51.  
  52.  
  53. end.
  54.  
« Last Edit: February 10, 2025, 06:43:18 pm by Hansvb »

zeljko

  • Hero Member
  • *****
  • Posts: 1718
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Read Excel file with fpspreadsheet.
« Reply #1 on: February 09, 2025, 08:17:38 pm »
Add fpsallformats unit into uses clause.

Hansvb

  • Hero Member
  • *****
  • Posts: 754
Re: Read Excel file with fpspreadsheet.
« Reply #2 on: February 10, 2025, 06:43:00 pm »
I had completely missed that. Thank you.

 

TinyPortal © 2005-2018