1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
| unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
StdCtrls, Variants, ComObj;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
var OpenOffice, Bureau, Document : Variant;
properties,CoreServ,prop : Variant;
vSheet,vCell : Variant;
n : Integer;
OO_FileName : WideString;
function FileToURL(F : String) : String;
var i : Word;
R : String;
begin
R:='file:///'+F;
// transforme le nom du fichier en adresse URL
while (Pos('\',R)>0) do {les \ en /}
begin
i:=Pos('\',R);
Delete(R,i,1);
Insert('/',R,i);
end;
while (Pos(' ',R)>0) do {les espaces en %20}
begin
i:=Pos(' ',R);
Delete(R,i,1);
Insert('%20',R,i);
end;
result:=R;
end;
begin
if (VarIsEmpty(OpenOffice) or VarIsNull(OpenOffice)) then
OpenOffice:=CreateOleObject('com.sun.star.ServiceManager');
if not(VarIsEmpty(OpenOffice) or VarIsNull(OpenOffice)) then
begin
if (VarIsEmpty(Bureau) or VarIsNull(Bureau)) then
Bureau:= OpenOffice.CreateInstance('com.sun.star.frame.Desktop');
end;
if (VarIsEmpty(Bureau) or VarIsNull(Bureau)) then
begin
MessageDlg('Le service Open Office n''est pas ouvert',mtError,[mbOk],0);
Exit;
end;
properties:=VarArrayCreate([0,0],varVariant);
CoreServ:= OpenOffice.CreateInstance('com.sun.star.reflection.CoreReflection');
CoreServ.forName('com.sun.star.beans.PropertyValue').CreateObject(prop);
prop.name:='Hidden';
prop.Value:=True;
properties[0]:=prop;
if FileExists('C:\MESSAROUND\test.ods')
then
OO_FileName:=FileToURL('C:\MESSAROUND\test.ods')
else
OO_FileName:='private:factory/scalc';
Document := Bureau.LoadComponentFromURL(OO_filename,
'_blank',
0,
properties);
if (VarIsEmpty(Document) or VarIsNull(Document)) then
begin
MessageDlg('Le fichier n''est pas ouvert',mtError,[mbOk],0);
Exit;
end;
vSheet:=Document.getSheets.getByName('Feuille1');
if (VarIsEmpty(vSheet) or VarIsNull(vSheet)) then
begin
MessageDlg('La Feuille n''est pas ouverte',mtError,[mbOk],0);
Exit;
end;
OpenOffice:=unAssigned;
end; |
Partager