Ci-joint le fichier que j'ai t'envoyé avant (delphi)
 
 

-----Message d'origine-----
De : Cezame Concept [mailto:[EMAIL PROTECTED] 
Envoyé : jeudi 2 mars 2006 10:56
À : prog@fr.openoffice.org
Objet : RE: [prog] RE : [prog] VB et commandes UNO

Ci-joint le code de mon projet VB Express 2005


-----Message d'origine-----
De : Didier Dorange-Pattoret [mailto:[EMAIL PROTECTED] 
Envoyé : jeudi 2 mars 2006 09:33
À : prog@fr.openoffice.org
Objet : Re: [prog] RE : [prog] VB et commandes UNO

Bonjour,

Si cela t'intéresse, j'ai en réserve qq fonctions du type ConvertToUrl
Cezame Concept a écrit :

> Merci pour ton aide …
>
> Je vais tenter de créer un assemblage .net avec l’ensemble des 
> fonctions principales pour oOWriter
>
Cela m'intéresse ...

> puis je m’attacherai a oOCalc …
>
> Je te fais parvenir le résultat de mon travail dès que j’ai quelque 
> chose qui tourne bien …
>
> ------------------------------------------------------------------------
>
> *De :* Didier Dorange-Pattoret [mailto:[EMAIL PROTECTED]
> *Envoyé :* jeudi 2 mars 2006 09:21
> *À :* prog@fr.openoffice.org
> *Objet :* Re: [prog] RE : [prog] VB et commandes UNO
>
> Bonjour,
>
> Le code ci-dessous fonctionne à merveille avec VB express 2005:
>
>
>    Public Function ConvertToUrl(ByVal strFile As String) As String
>
>        strFile = Replace(strFile, "\", "/")
>
>        strFile = Replace(strFile, ":", "|")
>
>        strFile = Replace(strFile, " ", "%20")
>
>        strFile = "file:///" <file:///%5C%5C> + strFile
>
>        ConvertToUrl = strFile
>
>    End Function
>
>    Public Function MakePropertyValue(ByVal cName As String, ByVal uValue
As VariantType) As Object
>
>        Dim oStruct, oServiceManager As Object
>
>        oServiceManager = CreateObject("com.sun.star.ServiceManager")
>
>        oStruct =
oServiceManager.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
>
>        oStruct.Name = cName
>
>        oStruct.Value = uValue
>
>        MakePropertyValue = oStruct
>
>    End Function
>
> 
>
> 
>
>End Module
>
>

-- 
Didier Dorange-Pattoret

http://www.dmaths.org
http://sesamath.net

S'inscrire à la liste de diffusion de dmaths: [EMAIL PROTECTED]
Ses archives: http://listes.dmaths.org/wws/arc/users
Les Forums: http://www.dmaths.org/modules.php?name=Forums
Mailing List in english:
http://www.dmaths.org/modules.php?name=Content&pa=showpage&pid=9

Le livre de référence pour OpenOffice.org2 :
http://www.amazon.fr/exec/obidos/ASIN/2212116381/dmaths-21
Programmation OpenOffice.org2 :
http://www.amazon.fr/exec/obidos/ASIN/2212117639/dmaths-21

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

----------------------------------------------------------------------------
-----------
Wanadoo vous informe que cet  e-mail a ete controle par l'anti-virus mail. 
Aucun virus connu a ce jour par nos services n'a ete detecte.



unit OOoWriter;
interface
uses ComObj,Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, 
Dialogs,ShlObj,Activex;

type
  TOOoWriter = class(TObject)
  private
    fOpenOffice : Variant;
//    fDocument : Variant;
    fDocument : OleVariant;
    fConnected : boolean;
    fDocumentOpened : boolean;
    fDesktop : Variant;
    oEventListener : Variant;
    function MakePropertyValue(PropName:string; PropValue:variant):variant;
    procedure pSetEvent(strEventName:string);
  public
     Constructor Create;
     destructor Destroy; override;

     function Connect : boolean;
     procedure Disconnect;

     function OpenDocument(Filename:string):boolean;
     procedure SaveToPDF(FileName:string);
     procedure CloseDocument;
     function  StartListening() : Boolean;
     Procedure DocCloseListener_disposing(oEvent : TObject);

  end;

 Implementation
{ TOOoWriter }
uses
OOoTools;
procedure TOOoWriter.CloseDocument;
begin
    if fDocumentOpened then
    begin
      showmessage('ok');
       fDocument.Close(false);

       fDocumentOpened := false;
       fDocument := Unassigned;

       fDesktop.Terminate;
       fDesktop := UnAssigned;
    end; 
end; 

function TOOoWriter.Connect: boolean;
begin 
    if  VarIsEmpty(fOpenOffice) then
        fOpenOffice := CreateOleObject('com.sun.star.ServiceManager');

    fConnected := not (VarIsEmpty(fOpenOffice) or VarIsNull(fOpenOffice));
    Result := fConnected;
end;

constructor TOOoWriter.Create;
begin
  inherited; 
  CoInitialize(nil);
end;

destructor TOOoWriter.Destroy; 
begin 
  CoUninitialize;
  inherited;
end; 

procedure TOOoWriter.Disconnect; 
begin
    if fDocumentOpened then 
       CloseDocument;

    fConnected := false;
    fOpenOffice := Unassigned;
end;

function TOOoWriter.MakePropertyValue(PropName: string;
  PropValue: variant): variant;
var
   Struct: variant;
begin
    Struct := fOpenOffice.Bridge_GetStruct('com.sun.star.beans.PropertyValue');
    Struct.Name := PropName;
    Struct.Value := PropValue;
    Result := Struct;
end;

function TOOoWriter.OpenDocument(Filename: string): boolean;
var
   wProperties : Variant;
begin
   if not fConnected then
      abort;

   pSetEvent('OnUnload');
   fDesktop := fOpenOffice.createInstance('com.sun.star.frame.Desktop');

//   wProperties := VarArrayCreate([0, 0], varVariant);
//   wProperties[0] := MakePropertyValue('Hidden', True);
   wProperties := VarArrayCreate([0, 2], varVariant);
   wProperties[0] := MakePropertyValue('Hidden', False);
//   wProperties[1] := MakePropertyValue('OnUnload','///CloseDocument');


//[FAB]
//   fDocument := fDesktop.loadComponentFromURL(  'file:///'+ 
StripString(FileName, ['\'], '/') , '_blank', 0, wProperties);
    fDocument := fDesktop.loadComponentFromURL(  'file:///'+ FileName , 
'_blank', 0, wProperties);

   fDocumentOpened := not (VarIsEmpty(fDocument) or VarIsNull(fDocument));
//   fDocument.OnClose := CloseDocument;
   result := fDocumentOpened;
end;

procedure TOOoWriter.pSetEvent(strEventName: string);
var
  GlobalEvent : Variant;
  MyEvent : Variant;
begin
  MyEvent := VarArrayCreate([0, 1], varVariant);
//  MyEvent[0] := MakePropertyValue('EventType', 'Basic');
  MyEvent[0] := MakePropertyValue('EventType', 'Basic');
  MyEvent[1] := MakePropertyValue('Script', 
'macro:///application.OOoWriter.CloseDocument()');
  //macro:///<Library>.<Module>.<Method(args)>
//  macro://./<Library>.<Module>.<Method(args)>
{monEvent(1).name = "Script"                                s
if SetOrNot = 1 then
        monEvent(1).value="macro:///myLib.myModule.mySub()"
else
        monEvent(1).value=""
endif}

{'for only bind to the document
'lesEvents = thisComponent.events
'lesEvents.replaceByName("OnStartApp", monEvent())}

GlobalEvent := createUnoservice('com.sun.star.frame.GlobalEventBroadcaster');
GlobalEvent.Events.ReplaceByName(strEventName, MyEvent);


end;

procedure TOOoWriter.SaveToPDF(FileName: string);
var
   wProperties: variant;
begin
   if not (fConnected and fDocumentOpened) then
      abort;

   wProperties := VarArrayCreate([0, 0], varVariant);
   wProperties[0] := MakePropertyValue('FilterName', 'writer_pdf_Export');
//   fDocument.StoreToURL('file:///'+ StripString(FileName, ['\'], '/'), 
wProperties);
   fDocument.StoreToURL('file:///'+ FileName, wProperties);
end;
//////////////////////////////////////////
{type TOfficeTextDocument = class
 (...)
   private
      ServiceManager: Variant;
      StarDesktop: Variant;
      Document: Variant;

      procedure DocCloseListener_disposing( oEvent : TObject );
emd;}

//2do


function TOOoWriter.StartListening() : Boolean;
Begin
//  oEventListener := CreateUnoListener( 
'DocCloseListener_','com.sun.star.document.XEventListener' );
  oEventListener := CreateUnoService( 
'DocCloseListener_','com.sun.star.document.XEventListener' );

  fDocument.addEventListener( oEventListener );
End;


procedure TOOoWriter.DocCloseListener_disposing(oEvent : TObject);
begin
 MessageDlg('Zamykamy !!! ',mtWarning,[mbOK],0);
end;




end.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Répondre à