Using fpSptreadshet in Free Pascal? lazarus / 64-FPC development ---------------------------------------------------------------------- mellotronworker · 2023-02-25 12:26 Can I use fpSpreadsheet in FP?  I am NOT interested in having to use Lazarus, just FP. I would have expected to see something about the dependencies required for the libray when I downloaded it, but it seems to assume that I am using Lazarus? thanks M ---------------------------------------------------------------------- marcov · 2023-02-25 13:46 Yes.  In the past I have made some simple console programs that set up excel sheets with e.g. schedule information and fill it with some strandard posts. Nothing fancy, but you can just do Code: [Select]  MyWorkbook := TsWorkbook.Create;   MyWorksheet := MyWorkbook.AddWorksheet('Sheet'); in a console program ---------------------------------------------------------------------- wp · 2023-02-25 15:07 All the demo programs in folder examples/read_write of the fpspreadsheet installation have a command-line user interface and do not require Lazarus. If you only want to use FPC you only need the laz_fpspreadsheet package (and laz_fpspreadsheet_crypto if you want to read encrypted Excel files). The corresponding source files are in folder source/common (and source/crypto, respectively). ---------------------------------------------------------------------- dseligo · 2023-02-25 17:07 As I plan to use fpspreadsheet in headless Linux server I am also interested in this. I used FP IDE, FPC version 3.2.0 on Debian. Steps: - get fpspreadsheet 1.14 from lazarus-ccr - get 'lazutils' directory from Lazarus' Gitlab repository - set appropriate directories for units and include files - because of use C-like operators (I don't like them) in lazutf8.pas they had to be enabled in Compiler options - set Compiler Mode to 'Object Pascal extension on' ({$mode objfpc} in main source didn't work). Otherwise, Result variable isn't enabled in functions and consequently compiling fpscrypto.pas fails. Code to create test Excel file: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program test_excel; uses SysUtils, fpspreadsheet, xlsxooxml; var excel: TsWorkbook;    list: TsWorkSheet;    i: Integer; begin  excel := TsWorkbook.Create;  try    list := excel.AddWorksheet('Test sheet');  i := 0;    list.WriteCellValueAsString(i, 0, 'ID');    list.WriteCellValueAsString(i, 1, 'Value');     While i < 20 do begin      inc(i);       list.WriteCellValueAsString(i, 0, IntToStr(i));    list.WriteNumber(i, 1, i * 10);    end;     inc(i);    list.WriteCellValueAsString(i, 0, 'Total:');    list.WriteFormula(i, 1, '=sum(B2:B' + IntToStr(i) + ')');     excel.WriteToFile('test.xlsx', True);  finally    excel.Free;  end;end. ---------------------------------------------------------------------- wp · 2023-02-25 17:28 Quote from: dseligo on February 25, 2023, 06:07:35 pm- set Compiler Mode to 'Object Pascal extension on' ({$mode objfpc} in main source didn't work). Otherwise, Result variable isn't enabled in functions and consequently compiling fpscrypto.pas fails. Just added the missing {$mode objfpc}{$H+} directive to the fpscrypto and xlsxooxml_crypto units. ---------------------------------------------------------------------- dseligo · 2023-02-25 21:33 Quote from: wp on February 25, 2023, 06:28:46 pmQuote from: dseligo on February 25, 2023, 06:07:35 pm- set Compiler Mode to 'Object Pascal extension on' ({$mode objfpc} in main source didn't work). Otherwise, Result variable isn't enabled in functions and consequently compiling fpscrypto.pas fails. Just added the missing {$mode objfpc}{$H+} directive to the fpscrypto and xlsxooxml_crypto units. Great, thank you. Would be possible to change lazutf8.pas (from lazutils) C-style operators to Pascal style? They are in 5 places in that file. Then it wouldn't be necessary to switch C-style operators in compiler options. ---------------------------------------------------------------------- wp · 2023-02-25 21:51 Post the issue in the bugtracker. ---------------------------------------------------------------------- dseligo · 2023-02-25 22:53 Quote from: wp on February 25, 2023, 10:51:05 pmPost the issue in the bugtracker. https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/40133 ---------------------------------------------------------------------- Weiss · 2023-03-15 03:48 Quote from: dseligo on February 25, 2023, 06:07:35 pmAs I plan to use fpspreadsheet in headless Linux server I am also interested in this. I used FP IDE, FPC version 3.2.0 on Debian. Steps: - get fpspreadsheet 1.14 from lazarus-ccr - get 'lazutils' directory from Lazarus' Gitlab repository - set appropriate directories for units and include files - because of use C-like operators (I don't like them) in lazutf8.pas they had to be enabled in Compiler options - set Compiler Mode to 'Object Pascal extension on' ({$mode objfpc} in main source didn't work). Otherwise, Result variable isn't enabled in functions and consequently compiling fpscrypto.pas fails. Well this is exactly where I struggle - appropriate directories for units and include files. Whenever I try compiling the FPSpreadsheet, compilation fails because of missing files. Can we go step-by-step what do I move from Github, and where do I put it? I need to use FPSpreadsheet in Free Pascal, just like OP. ---------------------------------------------------------------------- TRon · 2023-03-15 04:26 Quote from: Weiss on March 15, 2023, 04:48:33 amCan we go step-by-step what do I move from Github, and where do I put it? No need for github. 1 - download: https://packages.lazarus-ide.org/FPSpreadsheet.zip 2 - download: https://sourceforge.net/projects/lazarus/files/Lazarus%2 0Zip%20_%20GZip/Lazarus%202.2.4/lazarus-2.2.4-0.zip in your project directory 3 - make a directory "fps" (for FP SpreadSheet) 4 - make a directory "lazutils" (for lazutils) 5 - from FPSpreadsheet.zip, extract the contents of the directory /fpspreadsheet/source into the created "fps" directory. 6 - from lazarus-2.2.4-0.zip, extract the contents of the directory /lazarus/components/lazutils into the created "lazutils" directory 7 - write your test program (for example test_excel from user dseligo) and save the source-code to your project directory. 8 - compile, f.e. test_excel.pas from commandline in your project directroy with: $> fpc -B -Mobjfpc test_excel.pas -Fu./fps/* -Fi./fps -Fu./lazutils Note that you can store the extracted content from the zip files into another location if you wish to do so but that you need to modify the -Fu and -Fi options accordingly. You could for instance store the extracted contents to a more global location (such as the location of your other 3th party installed libraries) and add the additional search path options  -Fu and -Fi to your fpc.cfg file ---------------------------------------------------------------------- dseligo · 2023-03-15 13:36 In addition what Tron wrote. The example I posted was compiled under Free Pascal IDE. FPspreadsheet is placed in my user directory in fpc/fpspreadsheet directory and lazutils is under fpc/lazutils directory. In Free Pascal IDE I added three lines in 'Options/Directories'. In 'Options/Directories/Units' I added: Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ../fpc/fpspreadsheet/source/common../fpc/lazutils And in 'Options/Directories/Include files' I added: Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ../fpc/fpspreadsheet/source Lazarus developers don't want to change C style operators to Pascal in file lazutils/lazutf8.pas, so you have to either turn on compiler option 'C like operators' or change Result+= to Result := Result + in 5 places in that file.