Recent

Author Topic: ODS --> XLS  (Read 10786 times)

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
ODS --> XLS
« on: August 24, 2010, 11:14:06 am »
Does anyone know how to convert a format .ODS into .Xls with lazarus? Is urgent thanks!
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

fabienwang

  • Sr. Member
  • ****
  • Posts: 449
  • Lazarus is the best
    • My blog
Re: ODS --> XLS
« Reply #1 on: August 24, 2010, 11:38:18 am »
I suggest you to look at the OpenOffice sources, as OpenOffice is able to save files as XLS.
I'm using Arch Linux.
Known for: CPickSniff, OpenGrabby
Contributed to: LazPaint

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: ODS --> XLS
« Reply #2 on: August 24, 2010, 11:55:28 am »
OpenOffice is not written in Java? I do not know Java! I could help you?
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1927
Re: ODS --> XLS
« Reply #3 on: August 24, 2010, 12:17:08 pm »

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: ODS --> XLS
« Reply #4 on: August 24, 2010, 12:30:57 pm »
This is trivial with fpspreadsheet. I added an example here:

http://wiki.freepascal.org/FPSpreadsheet#Converting_between_two_spreadsheet_formats

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: ODS --> XLS
« Reply #5 on: August 24, 2010, 02:26:40 pm »
It works, but dates do not understand why me and then I did not read the results! Does anyone know why?  :o



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.
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: ODS --> XLS
« Reply #6 on: August 24, 2010, 04:57:57 pm »
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

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: ODS --> XLS
« Reply #7 on: August 24, 2010, 05:12:44 pm »
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!
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: ODS --> XLS
« Reply #8 on: August 25, 2010, 07:51:43 am »
Help  :o
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: ODS --> XLS
« Reply #9 on: August 25, 2010, 09:15:27 am »
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!

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

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: ODS --> XLS
« Reply #10 on: August 25, 2010, 09:45:12 am »
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.
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: ODS --> XLS
« Reply #11 on: August 25, 2010, 10:28:05 am »
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

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: ODS --> XLS
« Reply #12 on: August 25, 2010, 10:34:11 am »
Ok Thanks
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

 

TinyPortal © 2005-2018