2014-11-03 15:34:57 +00:00
|
|
|
unit main;
|
|
|
|
|
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
|
2015-01-30 14:48:51 +00:00
|
|
|
ComCtrls, ActnList, Menus, StdActns, Buttons,
|
2017-05-11 21:38:15 +00:00
|
|
|
fpstypes, fpspreadsheet, fpspreadsheetctrls, fpspreadsheetgrid, fpsActions,
|
|
|
|
fpsallformats;
|
2014-11-03 15:34:57 +00:00
|
|
|
|
|
|
|
type
|
|
|
|
|
2016-10-21 20:57:58 +00:00
|
|
|
{ TForm1 }
|
2014-11-03 15:34:57 +00:00
|
|
|
|
2016-10-21 20:57:58 +00:00
|
|
|
TForm1 = class(TForm)
|
|
|
|
ActionList1: TActionList;
|
|
|
|
FileExit1: TFileExit;
|
|
|
|
FileOpen1: TFileOpen;
|
|
|
|
FileSaveAs1: TFileSaveAs;
|
|
|
|
ImageList1: TImageList;
|
|
|
|
MainMenu1: TMainMenu;
|
2014-11-10 13:05:28 +00:00
|
|
|
MnuFile: TMenuItem;
|
2016-10-21 20:57:58 +00:00
|
|
|
MnuFileOpen: TMenuItem;
|
|
|
|
MnuFileSaveAs: TMenuItem;
|
|
|
|
MnuFileSeparator: TMenuItem;
|
|
|
|
MnuFileExit: TMenuItem;
|
|
|
|
MnuFormat: TMenuItem;
|
|
|
|
MnuFormatBold: TMenuItem;
|
|
|
|
MnuFormatItalic: TMenuItem;
|
|
|
|
MnuFormatUnderline: TMenuItem;
|
|
|
|
sWorkbookSource1: TsWorkbookSource;
|
|
|
|
sWorkbookTabControl1: TsWorkbookTabControl;
|
|
|
|
sWorksheetGrid1: TsWorksheetGrid;
|
|
|
|
sCellEdit1: TsCellEdit;
|
|
|
|
sCellIndicator1: TsCellIndicator;
|
|
|
|
sFontStyleAction1: TsFontStyleAction;
|
|
|
|
sFontStyleAction2: TsFontStyleAction;
|
|
|
|
sFontStyleAction3: TsFontStyleAction;
|
2014-11-17 16:59:22 +00:00
|
|
|
Panel2: TPanel;
|
2014-11-26 23:45:09 +00:00
|
|
|
FontColorCombobox: TsCellCombobox;
|
2016-10-21 20:57:58 +00:00
|
|
|
FontNameCombo: TsCellCombobox;
|
|
|
|
FontSizeCombo: TsCellCombobox;
|
2014-11-17 16:59:22 +00:00
|
|
|
Splitter2: TSplitter;
|
|
|
|
Splitter3: TSplitter;
|
|
|
|
ToolBar3: TToolBar;
|
2014-11-10 16:51:22 +00:00
|
|
|
ToolBar1: TToolBar;
|
2016-10-21 20:57:58 +00:00
|
|
|
ToolButton1: TToolButton;
|
2014-11-10 16:51:22 +00:00
|
|
|
ToolButton2: TToolButton;
|
|
|
|
ToolButton3: TToolButton;
|
2014-11-12 22:55:22 +00:00
|
|
|
ToolButton6: TToolButton;
|
|
|
|
ToolButton7: TToolButton;
|
|
|
|
ToolButton8: TToolButton;
|
2016-10-21 20:57:58 +00:00
|
|
|
procedure FileOpen1Accept(Sender: TObject);
|
|
|
|
procedure FileSaveAs1Accept(Sender: TObject);
|
2014-11-03 15:34:57 +00:00
|
|
|
private
|
2016-10-21 20:57:58 +00:00
|
|
|
|
2015-04-26 16:24:19 +00:00
|
|
|
protected
|
2016-10-21 20:57:58 +00:00
|
|
|
|
2014-11-03 15:34:57 +00:00
|
|
|
public
|
2016-10-21 20:57:58 +00:00
|
|
|
|
2014-11-03 15:34:57 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
var
|
2016-10-21 20:57:58 +00:00
|
|
|
Form1: TForm1;
|
2014-11-03 15:34:57 +00:00
|
|
|
|
2015-03-19 23:38:16 +00:00
|
|
|
|
2014-11-03 15:34:57 +00:00
|
|
|
implementation
|
|
|
|
|
|
|
|
{$R *.lfm}
|
|
|
|
|
2015-02-25 09:43:37 +00:00
|
|
|
uses
|
2016-10-21 20:57:58 +00:00
|
|
|
LCLIntf,
|
|
|
|
fpsUtils, fpsCSV;
|
2015-02-25 09:43:37 +00:00
|
|
|
|
2015-05-31 16:06:22 +00:00
|
|
|
|
2016-10-21 20:57:58 +00:00
|
|
|
{ TForm1 }
|
2014-11-03 15:34:57 +00:00
|
|
|
|
2016-10-21 20:57:58 +00:00
|
|
|
{ Loads the spreadsheet file selected by the FileOpen standard action }
|
|
|
|
procedure TForm1.FileOpen1Accept(Sender: TObject);
|
2016-10-12 22:40:48 +00:00
|
|
|
begin
|
2016-10-21 20:57:58 +00:00
|
|
|
sWorkbookSource1.AutodetectFormat := false;
|
|
|
|
case FileOpen1.Dialog.FilterIndex of
|
|
|
|
1: sWorkbookSource1.AutoDetectFormat := true; // All spreadsheet files
|
|
|
|
2: sWorkbookSource1.AutoDetectFormat := true; // All Excel files
|
|
|
|
3: sWorkbookSource1.FileFormat := sfOOXML; // Excel 2007+
|
|
|
|
4: sWorkbookSource1.FileFormat := sfExcel8; // Excel 97-2003
|
|
|
|
5: sWorkbookSource1.FileFormat := sfExcel5; // Excel 5.0
|
|
|
|
6: sWorkbookSource1.FileFormat := sfExcel2; // Excel 2.1
|
|
|
|
7: sWorkbookSource1.FileFormat := sfOpenDocument; // Open/LibreOffice
|
|
|
|
8: sWorkbookSource1.FileFormat := sfCSV; // Text files
|
2016-10-12 22:40:48 +00:00
|
|
|
end;
|
2016-10-21 20:57:58 +00:00
|
|
|
sWorkbookSource1.FileName :=FileOpen1.Dialog.FileName; // This loads the file
|
2016-10-12 22:40:48 +00:00
|
|
|
end;
|
|
|
|
|
2016-10-21 20:57:58 +00:00
|
|
|
{ Saves the spreadsheet to the file selected by the FileSaveAs1 action }
|
|
|
|
procedure TForm1.FileSaveAs1Accept(Sender: TObject);
|
2016-01-21 10:55:55 +00:00
|
|
|
var
|
2016-10-21 20:57:58 +00:00
|
|
|
fmt: TsSpreadsheetFormat;
|
2014-11-03 15:34:57 +00:00
|
|
|
begin
|
2016-01-21 10:55:55 +00:00
|
|
|
Screen.Cursor := crHourglass;
|
|
|
|
try
|
2016-10-21 20:57:58 +00:00
|
|
|
case FileSaveAs1.Dialog.FilterIndex of
|
|
|
|
1: fmt := sfOOXML; // Note: Indexes are 1-based here!
|
|
|
|
2: fmt := sfExcel8;
|
|
|
|
3: fmt := sfExcel5;
|
|
|
|
4: fmt := sfExcel2;
|
|
|
|
5: fmt := sfOpenDocument;
|
|
|
|
6: fmt := sfCSV;
|
|
|
|
7: fmt := sfWikiTable_WikiMedia;
|
2016-01-21 10:55:55 +00:00
|
|
|
end;
|
2016-10-21 20:57:58 +00:00
|
|
|
sWorkbookSource1.SaveToSpreadsheetFile(FileSaveAs1.Dialog.FileName, fmt);
|
2014-11-17 16:59:22 +00:00
|
|
|
finally
|
|
|
|
Screen.Cursor := crDefault;
|
2014-11-03 15:34:57 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|
|
|
|
|