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

Java, C++, C#, Delphi... - Using the UNO bridges
Post Reply
WilliamGorden
Posts: 3
Joined: Fri Jun 13, 2014 2:01 pm

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

Post 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???
LibreOffice 4.1.6.2 on Windows 8.1
User avatar
Villeroy
Volunteer
Posts: 31363
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

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

Post by Villeroy »

You can not use a program without running it.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
WilliamGorden
Posts: 3
Joined: Fri Jun 13, 2014 2:01 pm

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

Post 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.
LibreOffice 4.1.6.2 on Windows 8.1
Post Reply