2009-10-14 8 views
0

Je suis nouveau à OpenOffice et j'ai lu beaucoup d'articles à ce sujet. J'ai besoin de coder la fonctionnalité de fusion et publipostage en C# pour demander à OpenOffice d'effectuer une opération de fusion et publipostage sur un document fourni. J'ai vu beaucoup d'exemples de fusion et publipostage utilisant VB.NET mais quand je convertis le VB en C# le composant mailmerge de celui-ci manque toujours de créer correctement. Mon code est le suivant. J'ai commenté le code de fusion et publipostage car il ne compile pas avec lui. Comment est-ce que je corrigerais le code ainsi il a effectué le publipostage?Fusion et publipostage à partir d'un ensemble de données en C# ASP.NET

public int InitialiseOpenOffice() 
{ 
    // This is the document with the mail merge tags in that I want to be used as the source. 
    string filePathStr = "file:///C:/DotNetDev/MailMerge//MailMergeSample.doc"; 

    Type openOffice; 
    openOffice = Type.GetTypeFromProgID("com.sun.star.ServiceManager"); 
    object objServiceManager = System.Activator.CreateInstance(openOffice); 

    // arguments for IDispatch-call 
    object[] parameters = new object[1]; 
    parameters[0] = "com.sun.star.frame.Desktop"; 

    // arguments for document 
    object[] args = new object[4]; 
    args[0] = "private:factory/swriter"; 
    args[1] = "_blank"; 
    args[2] = 0; 
    args[3] = new object[] { }; 

    // arguments for document 
    object[] existingargs = new object[4]; 
    existingargs[0] = filePathStr; 
    existingargs[1] = "_blank"; 
    existingargs[2] = 0; 
    existingargs[3] = new object[] { }; 

    object startdesktop; 
    object doc; 
    try 
    { 
     startdesktop = (object)openOffice.InvokeMember("createInstance", 
     BindingFlags.InvokeMethod, null, 
     objServiceManager, parameters); 
     doc = startdesktop.GetType().InvokeMember("loadComponentFromUrl", 
     BindingFlags.InvokeMethod, null, startdesktop, existingargs); 

     object openOfficeServiceManagerObj = System.Activator.CreateInstance(openOffice); 

     // arguments for MailMerge 
     object[] mailMergeParameters = new object[1]; 
     mailMergeParameters[0] = "com.sun.star.text.MailMerge"; 
     // 
     // 
     // All the code up to this point works, but the code below doesn't. At this 
     // point OponOffice is open with the document I want to use in the mailmerge. 
     // 
     // 
     //Type t_OOo; 
     //t_OOo = Type.GetTypeFromProgID("com.sun.star.ServiceManager"); 
     //objServiceManager = System.Activator.CreateInstance(t_OOo); 
     //object oMailMerge; 
     //oMailMerge = t_OOo.InvokeMember("createInstance", BindingFlags.InvokeMethod, null, objServiceManager, new Object[] { "com.sun.star.text.MailMerge" }); 
     //oMailMerge.DocumentURL = "file:///C:/Users/me/Desktop/OpenOffice Investigation/mail merged.odt"; 
     //oMailMerge.DataSourceName = "adds"; 
     //oMailMerge.CommandType = 0; 
     //oMailMerge.Command = "adds"; 
     //oMailMerge.OutputType = 2; 
     //oMailMerge.execute(new Object[] { }); 

     if (doc == null) 
     { 
     return 1; // error!! 
     } 

    } 
    catch (Exception e) 
    { 
     string s = e.Message; 
     return 1; 
    } 

    return 0; 

} 

Répondre

0

On dirait que cela a été adressé à Mailmerge using OpenOffice ...

+0

Je l'ai déjà vu cette URL ne nulle part il vous dire comment faire le publipostage réel, il semble juste à la jupe sur le sujet. –

Questions connexes