Recent

Author Topic: BOF record not found when read excel file to fpspreadsheet  (Read 5341 times)

mrkwlee

  • New Member
  • *
  • Posts: 18
BOF record not found when read excel file to fpspreadsheet
« on: July 04, 2018, 10:54:36 am »
My system is  win 10, Lazarus 1.8.4,
An excel file is read and displayed normally but an error message "BOF record not found " is shown.
Can anyone please tell me why?

The follow is my code:

with OpenDialog1 do
  if Execute then
  begin
    sWorkBookSource1.FileName:=FileName;
    sWorkSheetGrid1.Enabled:=True;
    Screen.Cursor := crHourglass;
    try
      workbook := TsWorkbook.Create;
      try
        Workbook.Options := Workbook.Options + [boReadFormulas, boAutoCalc];
        Workbook.ReadFromFile(DataFileName, sfExcel2);
      finally
        Workbook.Free;
      end;
    finally
      Screen.Cursor := crDefault;
    end;
  end;                                     

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: BOF record not found when read excel file to fpspreadsheet
« Reply #1 on: July 04, 2018, 11:09:43 am »
Your code worked on my test if I remove sfExcel2. Are you sure you really need it? Have you tried to run the code without it?

Code: Pascal  [Select][+][-]
  1. Workbook.ReadFromFile(OpenDialog1.FileName);

Read more:
http://wiki.freepascal.org/FPSpreadsheet#Workbook

mrkwlee

  • New Member
  • *
  • Posts: 18
Re: BOF record not found when read excel file to fpspreadsheet
« Reply #2 on: July 04, 2018, 11:13:26 am »
Thanks for your prompt reply. I have tried without sfExcel2 but I still got the same error.

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: BOF record not found when read excel file to fpspreadsheet
« Reply #3 on: July 04, 2018, 11:21:42 am »
Can you send me the sample excel file, which can cause the error for me to test?

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: BOF record not found when read excel file to fpspreadsheet
« Reply #4 on: July 04, 2018, 07:23:01 pm »
"BOF record not found" indicates that the file which you are trying to load is not a binary Excel file: neither BIFF2, nor BIFF5 nor BIFF8 (all these must have a BOF = Begin-Of-File record)

What are you trying to achieve? Your code is very confusing:
  • sWorkBookSource1.FileName:=FileName; loads the file of the OpenDialog into the visual FPSpreadsheet controls.
  • But then you create another workbook whichs reads the loaded file a second time assuming that it is the ancient xls-BIFF2 format (sfExcel2), and destroy the workbook immediately afterwards. Why do you do this?
« Last Edit: July 04, 2018, 11:34:00 pm by wp »

mrkwlee

  • New Member
  • *
  • Posts: 18
Re: BOF record not found when read excel file to fpspreadsheet
« Reply #5 on: July 05, 2018, 09:30:46 am »
Dear Handoko
It works fine when sfExcel2 removed again. I think I have missed some unkown things. Thank you.

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: BOF record not found when read excel file to fpspreadsheet
« Reply #6 on: July 05, 2018, 07:26:33 pm »
Good to hear it works.

But, you should not be happy too early. When your not working code becomes working correctly without you fixing it, it usually means there is a 'hidden' bug. Something bad can happen in the future.

The most important thing about bug fixing is you must know exactly what you've done that makes the code to work correctly.

mrkwlee

  • New Member
  • *
  • Posts: 18
Re: BOF record not found when read excel file to fpspreadsheet
« Reply #7 on: July 06, 2018, 04:18:37 am »
Will test it for more situations.Thx

 

TinyPortal © 2005-2018