I am writing a program for using LibreOffice CLI
in C#.
I wanna load LibreOffice
Writer with some predefined saved file and then want to close the LibreOffice Writer.
I am able to load Writer with blank but didn't get how to open some specific file and after doing some work close the writer using the program.
Any help would be highly appreciated.
Here is the Code
using unoidl.com.sun.star.lang;
using unoidl.com.sun.star.uno;
using unoidl.com.sun.star.bridge;
using unoidl.com.sun.star.frame;
using uno.util;
using unoidl.com.sun.star.text;
using unoidl.com.sun.star.util;
public static void Main()
{
XComponentContext context = null;
context = Bootstrap.bootstrap();
if (context != null)
Console.WriteLine("Connected");
XTextDocument newDoc = openWriter(context);
}
private static XTextDocument openWriter(XComponentContext xContext)
{
//define variables
unoidl.com.sun.star.frame.XComponentLoader xCLoader;
unoidl.com.sun.star.text.XTextDocument xDoc = null;
unoidl.com.sun.star.lang.XComponent xComp = null;
try
{
// get the remote office service manager
unoidl.com.sun.star.lang.XMultiComponentFactory xMCF =
xContext.getServiceManager();
Object oDesktop = xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", xContext);
xCLoader = ((XComponentLoader)oDesktop);
//UnoRuntime.queryInterface(com.sun.star.frame.XComponentLoader.class,oDesktop);
unoidl.com.sun.star.beans.PropertyValue[] szEmptyArgs = new unoidl.com.sun.star.beans.PropertyValue[0];
string strDoc = @"private:factory/swriter";
xComp = xCLoader.loadComponentFromURL(strDoc, "_blank", 0, szEmptyArgs);
xDoc = ((XTextDocument)xComp);
}
catch (System.Exception e) { }
return xDoc;
}