Forum > Beginners

Export Stringgrid to an xlslx file.

(1/3) > >>

seghele0:
Using: Windows10 + Lazarus.
I hope to find a programmer willing to provide me the code to export the contents of a Stringgrid to an xlsx file.
A simple 'form' with one stringgrid and one button to activate the export.
This is far too complex for my low level of programming.
Thanks already.

winni:
Hi!

Save the StringGrid to a CSV 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";}};} ---StringGrid1.SaveToCSVFile('Filename.csv');
And then load the file into Excel.

Winni

seghele0:
Thanks, but it's not for a CSV, but for an XLSX.
I know I can open a CSV with Excel, but would like an XLSX file right away.
 :-[

 

wp:
Use fpspreadsheet; you can install it via the Online-Package-Manager. There's lots of documentation in the wiki:

* https://wiki.lazarus.freepascal.org/FPSpreadsheet
* https://wiki.lazarus.freepascal.org/FPSpreadsheet:_Examples
* https://wiki.lazarus.freepascal.org/FPSpreadsheet:_List_of_formulas
* https://wiki.lazarus.freepascal.org/FPSpreadsheet_tutorial:_Writing_a_mini_spreadsheet_application
* https://wiki.lazarus.freepascal.org/TsWorksheetGrid
To get you started I am attaching a simple demo which exports a stringgrid to xlsx (or LibreOffice ods if you uncomment the corresponding line). The demo assumes that there are specific data types in each column and converts the strings of the StringGrid to corresponding types so that the xlsx file contains real numbers or dates rather than strings.

seghele0:
Hero Member, thanks for the info.
Your code works fine, but the're only numbers in my application, positive and negative (-5;15;-5;-5)
What and where do I need to adjust?
Thanks.
 :)

Navigation

[0] Message Index

[#] Next page

Go to full version