eDocEngine VCL
Create documents and reports in 18 formats
Compatibility
Delphi C++Builder

Creating Excel spreadsheets (XLS) in Delphi and C++Builder

Learn to create XLS spreadsheets using eDocEngine VCL.
By Mamatha K.

eDocEngine VCL is a 100%-VCL document-creation and report-export component suite for Delphi/C++Builder developers. It can create documents in PDF and text formats. It can create spreadsheets in XLS, XLSX and CSV formats. (Actually, it can even create spreadsheets in ancient Quattro Pro, Lotus 1-2-3, DIF and SYLK formats.) It can also create images in an alphabet soup of formats. In all, eDocEngine has document-creation engines in 20 formats!

Yes, siree, Lotus 1-2-3!

While eDocEngine comes with its own content-creation API, it will also happily export content from the universal metafile format (EMF/WMF) as well. Apart from that, eDocEngine has controls that can automatically interface with popular Delphi reporting tools and export content. In other words, using eDocEngine, you can easily add additional file format support by simply dropping eDocEngine components to your reports.

In this article, we will see how to create Excel spreadsheets using the native content-creation API. eDocEngine has two Excel engines. One creates spreadsheets in the newer XLSX format and the other creates spreadsheets in Excel 95 format.

In the following code snippet, we create an XLS spreadsheet. The rows and columns are numbered from 0. To create cell content, TextOut method has been used.

public procedure TextOut(
    Row: Integer; 
    Column: Integer; 
    Text: WideString; 
    Alignment: TgtHAlignment; 
    CellType: TgtCellType
); virtual; overload;

public TgtHAlignment = (
  haLeft,
  haRight,
  haCenter,
  haJustify,
  haGeneral
);

public TgtCellType = (
  ctString,
  ctInteger,
  ctDouble,
  ctCurrency,
  ctTime,
  ctDate,
  ctDateTime,
  ctInteger_TS,
  ctDouble_TS,
  ctPercentage_FP,
  ctPercentage
);

For cell formulas, FormulaOut method has been used.

public procedure FormulaOut(
    Row: Integer; 
    Column: Integer; 
    Text: String; 
    Alignment: TgtHAlignment; 
    FormulaType: TgtExcelFormulaType
);

public TgtExcelFormulaType = (
  ftExpression,
  ftFunction
);

Here is the code snippet that creates the Excel spreadsheet.

procedure TForm17.Button1Click(Sender: TObject);
var
  gtXLSEngine1: TgtXLSEngine;
begin
  gtXLSEngine1 := TgtXLSEngine.Create(nil);
  with gtXLSEngine1 do begin
    // Set file name
    FileName := 'Sample.xls';
    // Create spreadsheet
    BeginDoc;
    // Add first row
    TextOut(0, 0, 'John Doe', haLeft, ctString);
    TextOut(0, 1, '53', haRight, ctInteger);
    // Add second row
    TextOut(1, 0, 'Jane Doe', haLeft, ctString);
    TextOut(1, 1, '23', haRight, ctInteger);
    // Add third row
    TextOut(5, 0, 'Total', haLeft, ctString);
    FormulaOut(5, 1, 'sum(b1:b4)',haRight, ftFunction);
    // Save spreadsheet
    EndDoc;
  end;
end;

Here is the output Excel spreadsheet.

Please note that there are other overloads of the TextOut that use doubles, rather than integers. They address columns first and then rows. To avoid confusion, use either row-column overloads shown above or the X-Y overloads shown below.

public procedure TextOut(
    X: Double; 
    Y: Double; 
    Text: WideString
); override;

public procedure TextOut(
    X: Double; 
    Y: Double; 
    Text: WideString; 
    WrapAtMargin: Boolean
); override;

Creating Excel sheets by hand can be tedious. You can easily export to Excel and other formats from popular reporting tools - AceReporter, DevExpress Express Printing System, FastReport, QuickReport, Rave Reports, ReportBuilder, TRichView, ScaleRichView ThtmlViewer and many others.

---o0O0o---

Our .NET Developer Tools
Gnostice Document Studio .NET

Multi-format document-processing component suite for .NET developers.

PDFOne .NET

A .NET PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, and bookmark PDF documents in .NET applications.

Our Delphi/C++Builder developer tools
Gnostice Document Studio Delphi

Multi-format document-processing component suite for Delphi/C++Builder developers, covering both VCL and FireMonkey platforms.

eDocEngine VCL

A Delphi/C++Builder component suite for creating documents in over 20 formats and also export reports from popular Delphi reporting tools.

PDFtoolkit VCL

A Delphi/C++Builder component suite to edit, enhance, view, print, merge, split, encrypt, annotate, and bookmark PDF documents.

Our Java developer tools
Gnostice Document Studio Java

Multi-format document-processing component suite for Java developers.

PDFOne (for Java)

A Java PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, bookmark PDF documents in Java applications.

Our Platform-Agnostic Cloud and On-Premises APIs
StarDocs

Cloud-hosted and On-Premises REST-based document-processing and document-viewing APIs

Privacy | Legal | Feedback | Newsletter | Blog | Resellers © 2002-2025 Gnostice Information Technologies Private Limited. All rights reserved.