Recent

Author Topic: FPSpreadsheet  (Read 303 times)

Chris

  • New Member
  • *
  • Posts: 28
FPSpreadsheet
« on: June 15, 2019, 03:27:49 pm »
Hi

I want to search the contents of an Excel file so I thought I'd start with the example on the FPSpreadsheet wiki, but I can't get it to compile.

Here's what I'm using, pasted straight from the wiki.
var
  MyWorkbook: TsWorkbook;
  MyWorksheet: TsWorksheet;
  MyRow, MyCol: Cardinal;
  MySearchParams: TsSearchParams;
begin
  MyWorkbook := TsWorkbook.Create;
  try
    MyWorkbook.ReadFromFile(AFileName);

    // Specify search criteria
    MySearchParams.SearchText := 'Hallo';
    MySearchParams.Options := [soEntireDocument];
    MySearchParams.Within := swWorkbook;

    // or: MySearchParaams := InitSearchParams('Hallo', [soEntireDocument], swWorkbook);

    // Create search engine and execute search
    with TSearchEngine.Create(MyWorkbook) do begin
      if FindFirst(MySearchParams, MyWorksheet, MyRow, MyCol) then begin
        WriteLn('First "', MySearchparams.SearchText, '" found in cell ', GetCellString(MyRow, MyCol));
        while FindNext(MySeachParams, MyWorksheet, myRow, MyCol) do
          WriteLn('Next "', MySearchParams.SearchText, '" found in cell ', GetCellString(MyRow, MyCol));
      end;
      Free;
    end;
  finally
    MyWorkbook.Free;
  end;
end;

I'm getting an error identifier not found on TSearchEngine, I've got fpsTypes, fpSpreadsheet, fpsSearch, fpsUtils, laz_fpspreadsheet in my uses is there another unit I should be adding, any help would be very gratefully received?

Win10 Lazarus V1.8 FPSpreadsheet 1.10.1
 

wp

  • Hero Member
  • *****
  • Posts: 6309
Re: FPSpreadsheet
« Reply #1 on: June 15, 2019, 04:13:45 pm »
There is a typo in the wiki article (I just fixed it): The class name of the search engine is TsSearchEngine, not TSearchEngine. With only a few exceptions the "s" is the characteristic prefix of the fpspreadsheet type names.

Your unit list is basically correct, except for laz_fpspreadsheet which is not needed. And when it comes to real reading of a file you must also specify the unit which implements the reader for the file format, or you simply add "fpsAllFormats" which activates the reader (and writers) for all supported file formats.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

Chris

  • New Member
  • *
  • Posts: 28
Re: FPSpreadsheet
« Reply #2 on: June 16, 2019, 12:52:04 am »
Many thanks it now works as I expected