This is how I export a dataset to excel using flexcel from tmssoftware. This example has the basic.
var
FileName: string;
XLS: TExcelFile;
Format: Tflxformat;
F1: integer;
Row: integer;
begin
if not DataSet.IsEmpty then
begin
XLS := TXlsFile.Create(True);
try
XLS.NewFile;
format := XLS.getDefaultFormat;
format.Font.Name := 'Times New Roman';
format.Font.Color := clwhite;
format.FillPattern.Pattern := TFlxPatternStyle.Solid;
format.FillPattern.FgColor := $00AE631E;
F1 := archivoxls.AddFormat(formato);
//Apply f1 format to the first row and first two columns
XLS.SetCellFormat(1,1,f1);
XLS.SetCellFormat(1,2,f1);
// set name of the fields
XLS.SetCellValue(1, 1, 'NAME FIELD ONE');
XLS.SetCellValue(1, 2, 'NAME FIELD TWO');
row := 2;
DataSet.First;
while NOT DataSet.Eof do
begin
XLS.SetCellValue(row, 1, DateToStr(DataSet['FIELDONE'])); //TYPE DATE
XLS.SetCellValue(row, 2, DataSet['FIELDTWO']); //TYPE STRING
Inc(row);
DataSet.Next;
end;
FileName := FormatDateTime('YYMMDD_hhmmnnss',now)+username+'.xls';
XLS.Save(UniServerModule.LocalCachePath + filename);
UniSession.SendFile(UniServerModule.LocalCachePath + filename);
finally
FreeAndNil(XLS);
end;
end;