Page 1 of 1

[c#] loadComponentFromURL doesn't work...

Posted: Fri Jun 13, 2014 2:31 pm
by WilliamGorden
I will start by saying that I'm new here.

I have found something strange that I could not find here in this forum, even after spending the last 2 days looking.

I will be glad to delete this if someone can refer me to a post handling this problem that I haven't found yet.

First off, here's my code:

Code: Select all

        private unoidl.com.sun.star.sheet.XSpreadsheetDocument GetSpreadSheetTemplate(string filename)
        {
            // If filename is empty create a new sheet.
            string loadUrl = "";
            if (string.IsNullOrEmpty(filename))
                loadUrl = "private:factory/scalc";
            else
                loadUrl = "file:///" + filename;
            
            // set load property
            unoidl.com.sun.star.beans.PropertyValue[] loadProps = new unoidl.com.sun.star.beans.PropertyValue[1];
            loadProps[0] = new unoidl.com.sun.star.beans.PropertyValue();
            loadProps[0].Name = "AsTemplate";
            loadProps[0].Value = new uno.Any(false);
        
            XComponentLoader aLoader = (XComponentLoader)mXMSFactory.createInstance("com.sun.star.frame.Desktop");
            XComponent xComponent = aLoader.loadComponentFromURL(loadUrl, "_blank", 0, loadProps);
            
            // return Spreadsheet Document
            return (unoidl.com.sun.star.sheet.XSpreadsheetDocument)xComponent;
        }
I am calling this from a c# programm to open a calc template that I hope to populate with a lot of data, however ...

This doesn't work at all UNLESS I have an instance of LibreOffice running with this document already opened in it or I use a blank filename to get the generic calc template. In that case a second window is opened with this document in read only mode.

Setting "AsTemplate" to true opens a second window with a this document as a new unnamed document that can be edited. That's part of what I want however ...

What I want is to open the document even when LO is NOT running. I only want to use this file as a template so that I only have set headers/footers, etc. in the template.

In fact, I thought after borrowing much of the above code in many other blog entries that this would work just fine.

What am I doing wrong here???

Re: [c#] loadComponentFromURL doesn't work...

Posted: Fri Jun 13, 2014 3:11 pm
by Villeroy
You can not use a program without running it.

Re: [c#] loadComponentFromURL doesn't work...

Posted: Fri Jun 13, 2014 3:23 pm
by WilliamGorden
Hi, thanks for the quick reply!!

I just ran this function with an empty filename parameter and it opened LO with the standard calc template.

LO was not running, as I called the function and it worked just fine.

It doesn't work when I give it a real filename and LO isn't running.

It also doesn't work if LO is running and the template file is NOT opened in LO!!

However if LO is running and the template file is opened in a LO-Window then it opens a second LO-Window with a new instance of the template-file without a name.

That is strange.