It works, but dates do not understand why me and then I did not read the results! Does anyone know why?
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
fpspreadsheet, fpsallformats, LclType;
type
{ TForm1 }
TForm1 = class(TForm)
Cmd_SelIn: TButton;
Cmd_Converti: TButton;
Label1: TLabel;
Label2: TLabel;
Txt_In: TEdit;
Txt_Out: TEdit;
OpenDialog1: TOpenDialog;
procedure Cmd_ConvertiClick(Sender: TObject);
procedure Cmd_SelInClick(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
const
INPUT_FORMAT = sfOpenDocument;
OUTPUT_FORMAT = sfExcel8;
var
MyWorkbook: TsWorkbook;
MyDir: string;
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Cmd_ConvertiClick(Sender: TObject);
var
Messaggio: PChar;
begin
MyDir := ExtractFilePath(ParamStr(0));
// Convert the spreadsheet
MyWorkbook := TsWorkbook.Create;
try
if FileExists(Txt_Out.Text)=true then
begin
Messaggio:=PChar('Esiste già il file: ' + Txt_Out.Text + '. Sostituirlo?');
if MessageDlg ('Domanda', Messaggio, mtConfirmation,[mbYes, mbNo, mbIgnore],0) = mrYes then
//if Application.MessageBox(Messaggio, 'DOMANDA' , MB_YesNo + MB_IconQuestion) = IdYes then
begin
DeleteFile(Txt_Out.Text);
end
else
begin
Exit;
end;
end;
MyWorkbook.ReadFromFile( Txt_In.Text, INPUT_FORMAT);
MyWorkbook.WriteToFile(Txt_Out.Text, OUTPUT_FORMAT);
Txt_In.Clear;
Txt_Out.Clear;
ShowMessage('TERMINATO');
finally
MyWorkbook.Free;
end;
end;
procedure TForm1.Cmd_SelInClick(Sender: TObject);
var
PathOut: string;
begin
OpenDialog1.filter := 'Open Office (*.ods)|*.ods';
if OpenDialog1.Execute then
begin
Txt_In.Text := OpenDialog1.Filename;
PathOut:=Txt_In.Text;
Txt_Out.Text := StringReplace(PathOut,'.ods','.xls', [rfReplaceAll]); //sostituisco il punto con la virgola
end;
end;
end.