Save and load Excel .XLSX files from grids in Delphi or C++Builder apps
The Microsoft Excel file as industry standard
The Excel .XLSX file format is these days a de facto standard file format to exchange all kinds of tabular data. As the information in an Excel sheet is 2 dimensional, a grid control is the most logical choice for viewing such data or to be the source of such data.
Hence, the idea to make it extremely easy to take advantage of the FlexCel technology to also allow to natively save and load .XLSX files in our grid components, in particular our VCL grid for Windows application development with Delphi or C++Builder as well as our FNC grid for cross-platform development for Windows, macOS, iOS, Android, Linux.
[adinserter block=”2″]
Bridge components
After hooking the grid to this component via a property Grid, import or export is as low-code as a single line of code:
To load .XLSX sheet data into a grid:
TMSFNCGridExcelImport1.Import('test.xlsx', 'my sheet');
In case you wish to work with multiple sheets at once, the bridge components can be connected to a TAdvGridWorkbook and multiple sheets will be imported or exported via the same functions.
To save the data from the grid to an .XLSX file:
TMSFNCGridExcelExport1.Export('test.xlsx');
and in addition to export to Excel files, there are methods:
TMSFNCGridExcelExport1.ExportPDF('test.pdf');
or
TMSFNCGridExcelExport1.ExportHTML('test.html');
to export the grid to PDF or HTML files.
By default, the TAdvGridExcelExport or TTMSFNCGridExcelExport take in account a lot of cell characteristics for the import or export. This includes:
- background color
- font color
- font name & size
- cell alignment
- cell pictures
- cell merging
- cell checkboxes
- cell sizes
- hyperlinks
There is further fine control over what grid and/or Excel features will be imported & exported via properties under:
TTMSFNCGridExcelImport.ImportOptions, TAdvGridExcelImport.ImportOptions and TTMSFNCGridExcelImport.ExportOptions, TAdvGridExcelExport.ExportOptions
Also, the bridge components also allow you to specify what range of cells to import or export. By default this is the range of used cells in the grid or Excel file, but via TTMSFNCGridExcelImport.LocationOptions, TAdvGridExcelImport.LocationOptions and TTMSFNCGridExcelImport.LocationOptions, TAdvGridExcelExport.LocationOptions you have fine-grained control over what range of cells will be involved in the export/import.
Finally, if you want to dynamically control in code additional formatting of cells, there is the TAdvGridExcelExport.OnCellExport() event that is triggered for every cell and allows to override in code the cell format to apply for example:
procedure TExampleForm.AdvGridExcelExport1ExportCell(Sender: TObject; var Args: TExportCellEventArgs); var Fm: TFlxFormat; begin //Format cells in column 3 with a specific format. if Args.GridCol = 3 then begin //We can't modify Args.CellFormat.Property directly, so we assign it to a variable. Fm := Args.CellFormat; Fm.Format := '00.00'; Args.CellFormat := Fm; end; end;
Discount offer!
If you do not own TMS VCL UI Pack, TMS FNC UI Pack, TMS FlexCel, purchase bundled new licenses at 20% discount as well!