| View previous topic :: View next topic |
| Author |
Message |
seddonym General User

Joined: 18 Oct 2008 Posts: 11
|
Posted: Tue Oct 28, 2008 3:53 am Post subject: [SOLVED] Hiding a Spreadsheet using Java |
|
|
Hello
Does anyone have any idea how to hide a calc spreadsheet from within Java?
It looks like the Spreadsheet service has an isVisible property but I can't figure out how to access/change it.
Thanks
Last edited by seddonym on Fri Oct 31, 2008 3:24 am; edited 1 time in total |
|
| Back to top |
|
 |
BrianS General User

Joined: 10 Jun 2008 Posts: 38
|
Posted: Tue Oct 28, 2008 5:17 am Post subject: Re: Hiding a Spreadsheet using Java |
|
|
| seddonym wrote: | Hello
Does anyone have any idea how to hide a calc spreadsheet from within Java?
It looks like the Spreadsheet service has an isVisible property but I can't figure out how to access/change it.
Thanks |
I know that in LotusScript all I have to do for any soffice application (calc, writer, base, etc...) is to issue the following:
| Code: |
Public Sub startspreadsheet()
Set oServiceManager = CreateObject("com.sun.star.ServiceManager")
Set oCoreReflection= oServiceManager.createInstance("com.sun.star.reflection.CoreReflection")
'Create the Desktop
Set oDesktop = oServiceManager.createInstance("com.sun.star.frame.Desktop")
'Open a new empty spreadsheet
Dim prop As New OOProperties
prop.addProperty "Hidden", True 'Decide to run Openoffice hidden in background or visible to the user
Set oDocument = oDesktop.loadComponentFromURL("private:factory/scalc", "_blank", 0, prop.Values)
End Sub
|
OOProperties is a class:
| Code: |
Class OOProperties
'I found this class in the OpenOffice forum and found it very usefull. Thanks for sharing it!
'This clase can be used to pass properties to OO Objects
'E.g. pass the Hidden=True property to the app object to run the application in the background
'If you do not have to set properties, you do not mandatory need this class in your code
Public vProp() As Variant
Public app As Variant
Public vStruct As Variant
Public bInz As Integer
Sub new()
Set App = createobject("com.sun.star.ServiceManager")
Set vStruct = App.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
End Sub
Sub addProperty(sName As String, vValue As Variant)
If bInz Then
Redim Preserve vProp(Ubound(vProp) + 1)
Else
Redim vProp(0)
End If
bInz = True
vStruct.Name = sName
vStruct.Value = vValue
Set vProp(Ubound(vProp)) = vStruct
End Sub
Property Get Values()
If Not bInz Then
Me.addProperty "Dummy!", 0
bInz = True
End If
Values = vProp
End Property
End Class
|
|
|
| Back to top |
|
 |
seddonym General User

Joined: 18 Oct 2008 Posts: 11
|
Posted: Tue Oct 28, 2008 6:26 am Post subject: |
|
|
Thanks for your reply.
I tried the following in Java, but it throws a com.sun.star.beans.UnknownPropertyException.
'sheet' is the spreadsheet I want to hide.
| Code: |
XPropertySet sheetProperties = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, sheet);
sheetProperties.setPropertyValue("Hidden", true);
|
EDIT: Rereading your post I may not have been clear, I want to hide just one of the spreadsheets, rather than the entire spreadsheet document. I'm actually coding a macro to run from within a Calc document. |
|
| Back to top |
|
 |
BrianS General User

Joined: 10 Jun 2008 Posts: 38
|
Posted: Tue Oct 28, 2008 6:42 am Post subject: |
|
|
| seddonym wrote: | Thanks for your reply.
I tried the following in Java, but it throws a com.sun.star.beans.UnknownPropertyException.
'sheet' is the spreadsheet I want to hide.
| Code: |
XPropertySet sheetProperties = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, sheet);
sheetProperties.setPropertyValue("Hidden", true);
|
EDIT: Rereading your post I may not have been clear, I want to hide just one of the spreadsheets, rather than the entire spreadsheet document. I'm actually coding a macro to run from within a Calc document. |
This is what happened when I recorded a macro in Calc (OOo 3.0 - OOBasic)
| Code: |
sub hiding
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
rem ----------------------------------------------------------------------
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "aTableName"
args1(0).Value = "Sheet1"
dispatcher.executeDispatch(document, ".uno:Hide", "", 0, args1())
end sub
|
Should be able to adapt that to Java in your environment... |
|
| Back to top |
|
 |
hanya Super User

Joined: 04 May 2005 Posts: 543 Location: Japan
|
Posted: Tue Oct 28, 2008 7:10 am Post subject: |
|
|
| seddonym wrote: | Thanks for your reply.
I tried the following in Java, but it throws a com.sun.star.beans.UnknownPropertyException.
'sheet' is the spreadsheet I want to hide.
| Code: |
XPropertySet sheetProperties = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, sheet);
sheetProperties.setPropertyValue("Hidden", true);
|
EDIT: Rereading your post I may not have been clear, I want to hide just one of the spreadsheets, rather than the entire spreadsheet document. I'm actually coding a macro to run from within a Calc document. |
try "IsVisible" property. |
|
| Back to top |
|
 |
panblackbean General User

Joined: 20 Oct 2008 Posts: 10
|
Posted: Tue Oct 28, 2008 7:20 pm Post subject: |
|
|
Hi BrianS,
I want to know how to hide the Calc window when openoffice is exporting the data,and show the window after the exporting data complete.
The problem is :
when calc is exporting the data.At this time if user close the calc window,the code will pop up a error prompt,and the date will not export completely.So I want the calc window hide when openoffice is exporting the data,and show the window after the exporting data complete. _________________ openoffice |
|
| Back to top |
|
 |
seddonym General User

Joined: 18 Oct 2008 Posts: 11
|
Posted: Wed Oct 29, 2008 2:51 am Post subject: |
|
|
Thanks Hanya, the 'IsVisible' property worked!
Here is the code:
| Code: |
private void hideSheet(XSpreadsheet sheet)
{
XPropertySet sheetProperties = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, sheet);
try {
sheetProperties.setPropertyValue("IsVisible", false);
} catch (Exception e) {
this.errorLog("Could not hide sheet");
}
}
|
(ErrorLog is my own function but you get the idea.)
Presumably this pattern can be used more generally for setting properties on Uno objects.
Thanks for your help. |
|
| Back to top |
|
 |
BrianS General User

Joined: 10 Jun 2008 Posts: 38
|
Posted: Thu Oct 30, 2008 6:38 am Post subject: |
|
|
| panblackbean wrote: | Hi BrianS,
I want to know how to hide the Calc window when openoffice is exporting the data,and show the window after the exporting data complete.
The problem is :
when calc is exporting the data.At this time if user close the calc window,the code will pop up a error prompt,and the date will not export completely.So I want the calc window hide when openoffice is exporting the data,and show the window after the exporting data complete. |
This bit of code will start up a calc document hidden.
| Code: |
Private Sub startspreadsheet()
Set objServiceManager = CreateObject("com.sun.star.ServiceManager")
Set objCoreReflection= objServiceManager.createInstance("com.sun.star.reflection.CoreReflection")
'Create the Desktop
Set objDesktop = objServiceManager.createInstance("com.sun.star.frame.Desktop")
'Open a new empty spreadsheet
Dim args()
Dim prop As New OOProperties
prop.addProperty "Hidden", True 'Decide to run Openoffice hidden in background or visible to the user
Set objDocument = objDesktop.loadComponentFromURL("private:factory/scalc", "_blank", 0, prop.Values)
End Sub
|
OOProperties is a class
| Code: |
Class OOProperties
'I found this class in the OpenOffice forum and found it very usefull. Thanks for sharing it!
'This clase can be used to pass properties to OO Objects
'E.g. pass the Hidden=True property to the app object to run the application in the background
'If you do not have to set properties, you do not mandatory need this class in your code
Public vProp() As Variant
Public app As Variant
Public vStruct As Variant
Public bInz As Integer
Sub new()
Set App = createobject("com.sun.star.ServiceManager")
Set vStruct = App.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
End Sub
Sub addProperty(sName As String, vValue As Variant)
If bInz Then
Redim Preserve vProp(Ubound(vProp) + 1)
Else
Redim vProp(0)
End If
bInz = True
vStruct.Name = sName
vStruct.Value = vValue
Set vProp(Ubound(vProp)) = vStruct
End Sub
Property Get Values()
If Not bInz Then
Me.addProperty "Dummy!", 0
bInz = True
End If
Values = vProp
End Property
End Class
|
As I posted in another thread, this is the LotusScript code we use for making a spreadsheet visible once it has been fully rendered... The command "Print" sends the text to the Status / Print area of a Lotus Notes client. The calls to wb.* go to a script library written in LotusScript that handle rendering a calc spreadsheet.
| Code: |
Print "Export Progress: Preparing spreadsheet, please wait..."
Call wb.setTotalCellCount(totalCells)
Call wb.render
Print "Export Progress: Spreadsheet completed!"
Call wb.MakeVisible()
|
The MakeVisible routine is in the script library written in LotusScript:
| Code: |
Sub MakeVisible()
' Get some other parts of the document.
Set oDocCtrl = objDocument.getCurrentController()
Set oDocFrame = oDocCtrl.getFrame()
Set oDocWindow = oDocFrame.getContainerWindow()
oDocWindow.setVisible( True )
End Sub
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|