{
excel5demo.dpr
Demonstrates how to write an Excel 5.x file using the fpspreadsheet library
You can change the output format by changing the OUTPUT_FORMAT constant
AUTHORS: Felipe Monteiro de Carvalho
}program excel5demo;{$mode delphi}{$H+}uses
Classes, SysUtils, fpstypes, fpspreadsheet, fpsallformats, laz_fpspreadsheet;const
OUTPUT_FORMAT = sfExcel5;var
MyWorkbook: TsWorkbook;
MyWorksheet: TsWorksheet;
MyFormula: TsRPNFormula;
MyDir:string;begin// Initialization
MyDir :=ExtractFilePath(ParamStr(0));// Create the spreadsheet
MyWorkbook := TsWorkbook.Create;try
MyWorksheet := MyWorkbook.AddWorksheet('My Worksheet');// Write some number cells
MyWorksheet.WriteNumber(0,0,1.0);
MyWorksheet.WriteNumber(0,1,2.0);
MyWorksheet.WriteNumber(0,2,3.0);
MyWorksheet.WriteNumber(0,3,4.0);// Write the formula E1 = A1 + B1
MyWorksheet.WriteFormula(0,4,'A1+B1');// Creates a new worksheet
MyWorksheet := MyWorkbook.AddWorksheet('My Worksheet 2');// Write some string cells
MyWorksheet.WriteText(0,0,'First');
MyWorksheet.WriteText(0,1,'Second');
MyWorksheet.WriteText(0,2,'Third');
MyWorksheet.WriteText(0,3,'Fourth');// Save the spreadsheet to a file
MyWorkbook.WriteToFile(MyDir +'test'+ STR_EXCEL_EXTENSION, OUTPUT_FORMAT);finally
MyWorkbook.Free;end;end.
P.S.
свой вариант 2 я создал как комбинацию 1-го (90%) и 2-го варианта
вместо
MyWorkbook.ReadFromFile('Путь к файлу.xls',sfExcel8);