* * *

Author Topic: FPSpreadsheet - problem when reading spreadsheet (External: SIGSEGV, xlsxooxml)  (Read 987 times)

matandked

  • New member
  • *
  • Posts: 14
 I have some experience in Python, R!, C# and VB, but I'm very beginner in Lazarus/Pascal/Delphi, so please forgive me if answer to my question is obvious.

I'm trying to write a simple application that reads an Excel workbook and generate another workbook with descriptive statistics of the cell values stored in input workbook.
I'm using Lazarus 1.6 (FPC 3.0) under 64-bit Ubuntu 16.04.1 LTS.
I downloaded FPSpreadsheet 1.6.2 from https://sourceforge.net/projects/lazarus-ccr/files/FPSpreadsheet/

My project) compiles, but regarding of trying to read xlsx or xls file (I store test data here), I receive following error message:

Project project1 raised exception class 'External: SIGSEGV'.
In file 'xlsxooxml.pas' at line 357


as you can see on following print screens

I read an Excel spreadsheet in following way:
Code: Pascal  [Select]
  1. skoroszyt_in.ReadFromFile(NazwaPliku);

(whole commit to repo for reading Excel file looks as follows:
https://github.com/kedziorm/FreePascal-import-eksport-Excela/commit/e594351aeb55379a78ecb07e06d44eb89d191c30

I have no idea if there's something wrong within my code, I installed library incorrectly or is it a bug in FPSpreadsheet

« Last Edit: January 29, 2017, 02:27:18 pm by matandked »

wp

  • Hero Member
  • *****
  • Posts: 3953
You do not create the workbook

Code: Pascal  [Select]
  1.      if OpenDialog1.Execute then
  2.      begin
  3.            NazwaPliku := OpenDialog1.FileName;
  4.            Diag := Concat('Nazwa pliku: ', NazwaPliku);
  5.            Label2.Caption:=Diag;
  6.            // PROBLEM: Regardling of opening XLSX or XLS I get the same error message
  7.            skoroszyt_in := TsWorkbook.Create;  // <--- added
  8.            skoroszyt_in.ReadFromFile(NazwaPliku);
  9.  
  10.            for i := 0 to skoroszyt_in.GetWorksheetCount() - 1 do
  11.            begin
  12.              arkusz_in := skoroszyt_in.GetWorksheetByIndex(i);
  13.              ShowMessage(arkusz_in.Name);
  14.              // Do something with MyWorksheet
  15.            end;
  16.  
  17.            // Is it a method to close the workbook?  
  18.            // skoroszyt_in.Destroy;    // <--- ok, in principle, but...
  19.            skoroszyt_in.Free;   // <--- better because it checks if skorosyt is nil
  20.      end;    

You can also attach projects here - it would have the advantage that users reading this post later will be able to look at the project even if the external site does not longer exist. For uploading pack the .pas, .lfm, .lpr and .lpi files (as well as auxiliary data files needed (such as the .xls and xlsx files here) into a single zip file. You can upload using the "Attachments and other options". Please don't add any files generated by the compiler (such as .exe, .ppu etc).

And another wish from a non-Polish (?) person which would make debugging your code a bit easier: I would appreciate if you would translate your code to English - it's much easier to understand another programmer's code if the words are understood.
« Last Edit: January 29, 2017, 03:36:13 pm by wp »
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

matandked

  • New member
  • *
  • Posts: 14
Thank you, it works now!

Sorry for Polish variable names - if I will need to ask another question, I will translate them.

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus