bassclub.blogg.se

Delphi read excel file
Delphi read excel file












delphi read excel file

TCellValue that will be one of the objects allowed in an Excel cell TXlsFile.GetCellValueIndexed will return a GetCellValue since you will only read the used cells. To get the value for a cell when looping a full sheet, use To get the value for a single cell, use TXlsFile.GetCellValue.

delphi read excel file

To read an Excel file you use the TXlsFile class, from where youĬan read and write to any Excel 2.0 or newer where the arrays are 1 based instead of 0įor i := 1 to StringGrid1.ColCount - 1 doįor j := 1 to StringGrid1.This demo is available in your FlexCel installation at \Demo\Delphi\Modules\10.API\20.Reading Files and also at https:​//​github.​com/​tmssoftware/​TMS-​FlexCel.​VCL-​demos/​tree/​master/​Delphi/​Modules/​10.​API/​20.​Reading Files OverviewĪ demo showing how to read the contents of an Excel file using FlexCel. Add 1 to allow for the fixed row and column, and to synch up with the Data, We know that what is being returned is a two dimensional array Get the number of columns and rows from the array itself. StringGrid1.RowCount := VarArrayHighBound(Data, 1) + 1 StringGrid1.ColCount := VarArrayHighBound(Data, 2) + 1 of 1 is for the fixed row and column, and to synch up with the Data End(xlDown) finds the last used cell in the indicated column Get tne range we want to extract, in this case all rows of columns H-J. procedure TForm1.Button1Click(Sender: TObject) Įxcel := CreateOleObject('Excel.Application') īook := ('E:\TempFiles\Test.xlsx') I've commented the code to make clear what it's doing. While it's not tailored to your specific example, it should give you the basic concepts of doing so (and cleaning up properly afterward) that you can adapt to your specific needs.

delphi read excel file

Here's an example of dynamically retrieving the content of three entire columns (H, I and J) from an Excel spreadsheet.














Delphi read excel file