Blog

All Blog Posts  |  Next Post  |  Previous Post

Introducing FNC Grid Excel Bridge components

Bookmarks: 

Tuesday, March 2, 2021

TMS Software Delphi  Components

In the last weeks, we've been working on a component to allow you to import and export FNC Grids to the xlsx file format. We've also used the opportunity to rename the existing "Grid Filters" and "FMX Grid Filters" to "VCL Grid Excel Bridge" and "FNC Grid Excel Bridge" because the word "Filter" has a different meaning in a grid. We hope the new "Bridge" naming proves less ambiguous.

Same as the "Filters" before, the new Bridge components are free, but they require to have both TMS FNC UI Pack and TMS FlexCel licenses.

You can get the components here:

And the documentation is available here:

So what is the state now if you want to export or import a grid to/from Excel?  We have the following choices:

  1. (VCL Only) You can use StringGrid.SaveToXLS and StringGrid.LoadFromXLS. Those methods will use OLE Automation under the hood, and so they require that Excel is installed in the machine. Because they need Excel, they can only work on Windows.
  2. You can use TAdvGridExcelIO (VCL), TTMSFMXGridExcelIO (FMX) and TTMSFNCGridExcelIO (FNC). Those components use an older trimmed-down FlexCel 3 to do their job. Because they use FlexCel 3, which predates the XLSX file format, they can only work with XLS files, not XLSX.
  3. You can use the "TMS Grid Excel Bridge" components. Those components use an existing  FlexCel 7 to do the work, and so they can export to xls and xlsx, but also HTML and PDF.  Because they require a FlexCel license, they can access the full FlexCel behind it, to do extra customization. Just as an an example: You could add conditional formats to the generated files, as shown in the example here: https://doc.tmssoftware.com/grid-excel-bridge/fnc/guides/user-guide.html#customizing-the-export.



Note: FNCGrid already supports exporting to PDF and HTML natively, you don't need the bridge components for that. But if you are customizing the xlsx output, you might want to have a PDF or HTML exported with those customizations, and that's where the Bridge's exporting to HTML and PDF can be useful.


Up to now, the "Bridges" had support for VCL Grids and FMX Grids. With the release of FNC Bridge, we are extending the first-class Excel exporting and importing to FNC.

Note that in FNC, we only support VCL and FMX at the moment (all platforms). We can't support Lazarus or WebCore because FlexCel doesn't support them yet.

So to finish this small post, I'd like to show how it works. We'll try adding export support for the FNC Grid in the "ClientDataset" demo. This is the grid:

TMS Software Delphi  Components

We dropped a TTMSFNCGridExcelExportComponent, and wrote the code:

TMSFNCGridExcelExport1.Export('r:\test.xlsx');

And we got this result:

TMS Software Delphi  Components

The checkboxes work in Excel, they are not images. But they will be exported as images to HTML and PDF.


Next, we tried with HTML:

  TMSFNCGridExcelExport1.ExportHtml('r:\test.html', THtmlExportMode.SingleSheet);

And we got:

TMS Software Delphi  Components

Finally we went for the PDF export. We could also have tried the one-liner, but in this case it would end up with 2 pages. The grid is too wide and the right part of it goes to the second page. But here is where the power of having full access to the FlexCel engine can help. We could export this file to xlsx, then set the print options in the xlsx file to fit to one page, and only then export to PDF:

    
  var xls := TXlsFile.Create(1, true);
  try
    TMSFNCGridExcelExport1.Export(xls);
    var Pdf := TFlexCelPdfExport.Create(xls, true);
    try
      xls.PrintToFit := true;
      xls.PrintNumberOfHorizontalPages := 1;
      xls.PageHeader := '&L FNC Grid Excel Export Demo&RPage &P of &N';
      Pdf.ExportAllVisibleSheets('r:\test.pdf', false, '');
    finally
      Pdf.Free;
    end;
  finally
    FreeAndNil(xls);
  end;
Just for fun, we also added a page header, and we could have customized the result a lot more. Like for example setting the PDF author or signing the PDF file.

Here is the PDF we got:

TMS Software Delphi  Components



Adrian Gallero


Bookmarks: 

This blog post has not received any comments yet.



Add a new comment:
Author:
Email:
  You will receive a confirmation mail with a link to validate your comment, so please use a valid email address.
 
Comment:
 
 

All fields are required.
 



All Blog Posts  |  Next Post  |  Previous Post