Tips and Frequently Asked Questions

  How to create an Excel file with a gradient in a cell, a protected sheet and an autofilter


Excel files can be very complex, and guessing how to for example add a gradient to a cell, or protect a sheet, or add an autofilter can get difficult.

To make it easier, FlexCel provides a very useful tool named APIMate that can "convert" an Excel file into FlexCel code, for either Delphi or C++ Builder.


It works like this: You create a file in Excel, and open it in APIMate (without closing Excel). It will tell you the Delphi or C++ code needed to create the file. Then you can make changes in Excel, save the file, and press “Refresh” in APIMate (all without closing Excel). It will tell you the code you need to modify the file from the old state to the new one.

We are now in position to answer the question at the top of this section: How to create a file with a gradient in a cell, a protected sheet and an autofilter? I created a simple file with those things in Excel, and APIMate gives back this code:

procedure CreateFile(const xls: TExcelFile);
var
  fmt: TFlxFormat;
  GradientStops: TArray<TGradientStop>;
  SheetProtectionOptions: TSheetProtectionOptions;

begin
  xls.NewFile(1, TExcelFileFormat.v2010);  //Create a new Excel file with 3 sheets.

  //Set the names of the sheets

xls.ActiveSheet := 1;
  xls.ActiveSheet := 1;  //Set the sheet we are working in.

  //Global Workbook Options
  xls.OptionsCheckCompatibility := false;

  //Printer Settings
  xls.PrintXResolution := 600;
  xls.PrintYResolution := 600;
  xls.PrintOptions := [TPrintOptions.Orientation];

  fmt := xls.GetCellVisibleFormatDef(3, 1);
  fmt.FillPattern.Pattern := TFlxPatternStyle.Gradient;
  SetLength(GradientStops, 2);
  GradientStops[0].Position := 0;
  GradientStops[0].Color := TExcelColor.FromTheme(TThemeColor.Background1);
  GradientStops[1].Position := 1;
  GradientStops[1].Color := TExcelColor.FromTheme(TThemeColor.Accent1);
  fmt.FillPattern.Gradient := TExcelLinearGradient_Create(GradientStops, 90);
  xls.SetCellFormat(3, 1, xls.AddFormat(fmt));

  //AutoFilter
  xls.SetAutoFilter(1, 3, 5);

  //Protection
  SheetProtectionOptions := TSheetProtectionOptions.Create(false);
    SheetProtectionOptions.Contents := true;
    SheetProtectionOptions.Objects := true;
    SheetProtectionOptions.Scenarios := true;
    SheetProtectionOptions.SelectLockedCells := true;
    SheetProtectionOptions.SelectUnlockedCells := true;
  xls.Protection.SetSheetProtection(''******'', SheetProtectionOptions);
end;

APIMate is not the panacea for all the questions, but it helps a lot answering many of those "how do I?" doubts. Remember to use it.



Pricing

Single Developer License Site License
 

TMS FlexCel for VCL & FMX


€ 210

65 yearly renewal
license for 1 developer


Includes
check  Full source code
check  Access to the TMS Support Center
check  Free updates and new releases
MOST POPULAR

TMS VCL Subscription


€ 895

450 yearly renewal
license for 1 developer


Includes
check  Full source code
check  Access to the TMS Support Center
check  Free updates and new releases
check  TMS FlexCel for VCL & FMX
check  All TMS VCL products
more_horiz  Discover more
BEST VALUE

TMS ALL-ACCESS


€ 1,795

575 yearly renewal
license for 1 developer


Includes
check  Full source code
check  Access to the TMS Support Center
check  Free updates and new releases
check  TMS FlexCel for VCL & FMX
check  All TMS VCL products
check  All TMS products
more_horiz  Discover more
All prices excl. VAT. Renewal price is subject to change and only valid up to 30 days after license has expired. After renewal period a discount price is offered to renew the license.

TMS ALL-ACCESS

key
Your unlimited access to all TMS products
local_offer
One money and time saving bundle

Free Trial

Start a free TMS FlexCel for VCL & FMX evaluation today!
RAD Studio

What our customers say

We had a very positive Flexcel talk in our meeting yesterday. Dave Martel was very positive about the product; the support; speed to fix an issue. By doing the talk he realised improvements over the years and has an amazing success story from analysing a large number of human created spreadsheets (1000’s of spreadsheets with 1000’s of readings). The speed of analysis allowed them to refine and re-train the importer to deal with human vagaries (comments / colour etc).

- Jason Chapman

Wow, I'm really impressed that you found this out in such a short time! Thanks especially for testing it with Softmaker Office itself and with some more elaborate spreadsheets, this makes me confident that it'll work with the "real life" files that I have to handle. Super service!

- Arthur Hoornweg

It's now very easy to build a report with the new Flexcel + Aurelius integration. It was so easy that I really thought I was doing something wrong. I will never go back to a report generator, Flexcel is way cooler and easier for reports

- Eduardo Elias

Another vote for Flexcel here, since the rewritten and updated Flexcel came out a year or two ago, I only use that. Mostly I use it to read XLS and XLSX files, which it does much faster and more flexibly than Excel automation, in my experience. If you also need to write XLS and XLSX files (which I do occasionally) Flexcel has the most amazing utility named 'ApiMate'. You can design your output report in Excel, including only a minimum of actual data, but with all the detailed formatting, headings, and column, row and cell properties you need. Then point ApiMate at the Excel file, and it generates a Delphi program to write the entire XLS file using the Flexcel API, with all the attributes matching those you created in Excel itself. It is then the work of a few moments to adapt the ApiMate-created functions to handle your real data. Magic! Flexcel support is prompt and helpful, too.

- Tim Frost

Thanks for an excellent product. I did have some issues Friday but these were expertly solved by Adrian Gallero over the weekend. I cannot recommend you products and service high enough. Thanks and kind regards

- Kevin Clegg

TMS WEB Core

language
Create modern web apps in Delphi & VSC
build_circle
Use Object Pascal code to build JavaScript apps