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
|
procedure TForm1.Button1Click(Sender: TObject);
var xNum_Feuille : integer;
xl : string;
i : integer;
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;
OpenDesktop := OpenOffice.createInstance('com.sun.star.frame.Desktop');
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; // ca cache pas la feuille mais openoffice
properties[0]:=prop;
Document := openDesktop.LoadComponentFromURL( 'private:factory/scalc', '_blank', 0, properties);
xNum_Feuille := 1;
MonClasseur := Document.getSheets;
xl := 'Feuille' + InttoStr(xNum_Feuille);
MaFeuille := MonClasseur.GetByName(xL); //'Feuille1'
try
Cellule := Mafeuille.getCellByPosition(0, 1);
Cellule.SetValue(1);
Cellule := Mafeuille.getCellByPosition(1, 1);
Cellule.SetValue(2);
Cellule := Mafeuille.getCellByPosition(2, 1);
Cellule.SetValue(3);
Cellule := Mafeuille.getCellByPosition(3, 1);
Cellule.SetValue(4);
Cellule := Mafeuille.getCellByPosition(4, 1);
Cellule.SetValue(5);
Cellule := Mafeuille.getCellByPosition(5, 1);
Cellule.SetFormula('=A2+B2+C2+D2+E2'); // ok
Cellule := Mafeuille.getCellByPosition(6, 1);
Cellule.SetFormula('=SUM(A2:E2)'); // ok
Cellule := Mafeuille.getCellByPosition(7, 1);
Cellule.SetFormula('=SOMME(A2:E2)'); // #NOM? donc SOMME fonctionne pas cellule transformée en =somme(A2:E2) :koi:
except
Showmessage('Erreur unknown');
end;
document.storeAsUrl('file:///c:/BAD/TESTS.ods', VarArrayCreate([0, -1], varVariant));
Document.dispose;
end; |
Partager