Forum > FPC development

Using fpSptreadshet in Free Pascal?

(1/3) > >>

mellotronworker:
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:
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: ---  MyWorkbook := TsWorkbook.Create;
  MyWorksheet := MyWorkbook.AddWorksheet('Sheet');

--- End code ---

in a console program

wp:
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:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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:

--- 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.

--- End quote ---
Just added the missing {$mode objfpc}{$H+} directive to the fpscrypto and xlsxooxml_crypto units.

Navigation

[0] Message Index

[#] Next page

Go to full version