ODS --> XLS lazarus / 16-Databases ---------------------------------------------------------------------- xinyiman · 2010-08-24 09:14 Does anyone know how to convert a format .ODS into .Xls with lazarus? Is urgent thanks! ---------------------------------------------------------------------- fabienwang · 2010-08-24 09:38 I suggest you to look at the OpenOffice sources, as OpenOffice is able to save files as XLS. ---------------------------------------------------------------------- xinyiman · 2010-08-24 09:55 OpenOffice is not written in Java? I do not know Java! I could help you? ---------------------------------------------------------------------- theo · 2010-08-24 10:17 http://wiki.freepascal.org/FPSpreadsheet ---------------------------------------------------------------------- felipemdc · 2010-08-24 10:30 This is trivial with fpspreadsheet. I added an example here: http://wiki.freepascal.org/FPSpreadsheet#Converting_between_two_spread sheet_formats ---------------------------------------------------------------------- xinyiman · 2010-08-24 12:26 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. ---------------------------------------------------------------------- felipemdc · 2010-08-24 14:57 Your description of the problem is too generic. You should explain exactly which part of the code doesn't work and what value the variables have at that point and which values you would expect them to have, or similar. ---------------------------------------------------------------------- xinyiman · 2010-08-24 15:12 Then the file becomes ODS me correctly where numbers and strings, but a column with the format set to date I do not back, and I leave the column blank in the output file! ---------------------------------------------------------------------- xinyiman · 2010-08-25 05:51 Help ---------------------------------------------------------------------- felipemdc · 2010-08-25 07:15 Quote from: xinyiman on August 24, 2010, 05:12:44 pmThen the file becomes ODS me correctly where numbers and strings, but a column with the format set to date I do not back, and I leave the column blank in the output file! This phrase isn't understandable. Try writing in italian and explain the problem in details including the following sections: 1> Expected behavior 2> Actual behavior And where exactly in the code things go wrong. ---------------------------------------------------------------------- xinyiman · 2010-08-25 07:45 Ok, il programma funziona bene, io gli passo il file .ods in input e gli passo il nome del file .xls che voglio in output, e l'output è corretto, solo che non mi considera le colonne che hanno il formato data! Le ignora completamente e quindi nell'output la colonna che dovrebbe contenere delle date è vuota. ---------------------------------------------------------------------- felipemdc · 2010-08-25 08:28 Either the ODS reader doesn's support dates or the XLS writer doesn't support them (or both). It needs to be improved to do this. ---------------------------------------------------------------------- xinyiman · 2010-08-25 08:34 Ok Thanks