Page 1 of 1

[Solved] Opening a Spreadsheet invisible

PostPosted: Fri Oct 07, 2011 11:50 am
by Peter18
A friendly hallo to anybody,

I open a spreadsheet, read data from it and close it. It would be nice, to open the spreadsheet invisible, because it may confuse a user if a window appeares an disappeares.

Thank you and have a nice day!

Peter

Re: Opening a Spreadsheet invisible

PostPosted: Fri Oct 07, 2011 2:48 pm
by FJCC
There is an example of using the Hidden propertyvalue here

Re: Opening a Spreadsheet invisible

PostPosted: Fri Oct 07, 2011 4:01 pm
by Peter18
Hallo FJCC,

thank you for your answer! I tried to do it with Delphi 4:
Code: Select all   Expand viewCollapse view
    OpenOffice   := CreateOleObject('com.sun.star.ServiceManager');
    Par          := OpenOffice.Bridge_GetStruct('com.sun.star.beans.PropertyValue');
    Par.Name     := 'Hidden';
    Par.Value    := False;

    StarDesktop  := OpenOffice.createInstance('com.sun.star.frame.Desktop');
    sv           := OpenOffice.createInstance('com.sun.star.ucb.FileContentProvider');
    Path         := sv.getFileURLFromSystemPath('', FilePath);
    excel        := StarDesktop.loadComponentFromURL( Path, '_blank', 0, Par );
    Sheet        := Vertrieb.excel.Sheets.getByName( WorkSheet );

But I get an OLE error: typeconflikt with "StarDesktop.loadComponentFromURL( Path, '_blank', 0, Par );" :(
With empty "Par" there is no error.

Greetings

Peter

Re: Opening a Spreadsheet invisible

PostPosted: Fri Oct 07, 2011 4:23 pm
by FJCC
The fourth argument of loadComponentFromURL has to be an array of PropertyValues. In Basic this could be done with
Code: Select all   Expand viewCollapse view
Dim args(0) as New com.sun.star.beans.PropertyValue
args(0).Name = "Hidden"
args(0).Value = False
...

and then using args() as the fourth argument of loadComponentFromURL. I expect in Delphi you would just declare an array of length one and set its element to be your variable Par.

Re: Opening a Spreadsheet invisible

PostPosted: Fri Oct 07, 2011 6:19 pm
by Peter18
Hallo FJCC.

thank you again. "Par" is a Variant. "OpenOffice.Bridge_GetStruct('com.sun.star.beans.PropertyValue');" creates a Structure of OO. Even if I declare "Par" as "Array of Variant" with length of 1, there is the same error. I think "Par.Value" is not ok. Delphi normaly uses 1 Byte for a Boolean, but in API I sometimes found "Longboolean". But it does'nt work too.

Greetings

Peter

Re: Opening a Spreadsheet invisible

PostPosted: Fri Oct 07, 2011 8:50 pm
by FJCC
You may well be right that the Value of the PropertyValue is causing trouble. I don't have any direct suggestions to deal with that. You might try installing the XRay object inspection tool and try different ways of setting the Value and then inspecting the result. There is a section in the XRay manual about using it with Delphi. There is also a mention of a Delphi_OOo tool that seems still to be available. That must surely have a way of dealing with PropertyValues.

Re: Opening a Spreadsheet invisible

PostPosted: Mon Oct 10, 2011 1:17 pm
by Peter18
Hello FJCC,

thank you for your answer. I forgot the line "Par := VarArrayCreate([0, 0], varVariant);" There were too much trees, so I didn't see the forest. ;)
Code: Select all   Expand viewCollapse view
    Par          := VarArrayCreate([0, 0], varVariant);
    OpenOffice   := CreateOleObject('com.sun.star.ServiceManager');
    Par[0]       := OpenOffice.Bridge_GetStruct('com.sun.star.beans.PropertyValue');
    Par[0].Name  := 'Hidden';         
    Par[0].Value := True;             

    StarDesktop  := OpenOffice.createInstance('com.sun.star.frame.Desktop');
    sv           := OpenOffice.createInstance('com.sun.star.ucb.FileContentProvider');
    Path         := sv.getFileURLFromSystemPath('', FilePath);
    excel        := StarDesktop.loadComponentFromURL( Path, '_blank', 0, Par );
    Sheet        := Vertrieb.excel.Sheets.getByName( WorkSheet );


Greetings