You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openoffice.apache.org by Subodh Asthana <as...@gmail.com> on 2012/03/05 11:10:55 UTC

Executing UNO Dispatcher in VBScript doesn't reflect any changes in ODS file

Executing UNO Dispatcher in VBScript doesn't reflect any changes in ODS file
http://stackoverflow.com/q/9562093/264668?sem=2

Following is the code that I wrote to try formatting ODS using VBSript. It
runs without any error but it *does not reflect any change* in the ODS file.

Dim propertyset(0)
Dim arg()
Set oServiceManager = CreateObject("com.sun.star.ServiceManager")
Set oDesktop = oServiceManager.createInstance("com.sun.star.frame.Desktop")
Set UnoObj = oServiceManager.createInstance("com.sun.star.frame.DispatchHelper")
sFileName = "D:\Untitled 1.ods"
sFileName = Replace (sFileName, "\", "/")
sURL = "file:///" & sFileName
Set oSpreadsheet = oDesktop.loadComponentFromURL(sURL, "_blank", 0,
arg)    'load existing spreadsheet

set oSheet1 = oSpreadsheet.getSheets.getByName( "Sheet1" )
set document   = oSpreadsheet.CurrentController.Frame

Set propertyset(0) = MakePropertyValue(oServiceManager, "ToPoint", "$A$1")
Call UnoObj.executeDispatch(document, ".uno:GoToCell", "", 0, propertyset)

Set propertyset(0) = MakePropertyValue(oServiceManager,
"BackgroundColor", 16711680)
Call UnoObj.executeDispatch(document, ".uno:BackgroundColor", "", 0,
propertyset)
oSpreadsheet.Close(True)
set UnoObj = Nothing
set oSpreadsheet = Nothing
set oDesktop = Nothing
set oServiceManager = Nothing

Function MakePropertyValue(oServiceManager, cName, uValue)
   Dim oStruct
   Set oStruct =
oServiceManager.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
   Set MakePropertyValue = oStruct
End Function

Re: Executing UNO Dispatcher in VBScript doesn't reflect any changes in ODS file

Posted by "F C. Costero" <fj...@gmail.com>.
I also don't see the Name and Value properties of the Property value
being set in the function. Try
Function MakePropertyValue(oServiceManager, cName, uValue)
  Dim oStruct
  Set oStruct =
oServiceManager.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
  oStruct.Name = cName
  oStruct.Value = uValue
  Set MakePropertyValue = oStruct
End Function

On Mon, Mar 5, 2012 at 7:18 AM, TJ Frazier <tj...@cfl.rr.com> wrote:
> Try adding a Store request:
>
>> Call UnoObj.executeDispatch(document, ".uno:BackgroundColor", "", 0,
>> propertyset)
> oSpreadsheet.Store()
>> oSpreadsheet.Close(True)
> Close won't do that for you.
> /tj/
>
>
> On 3/5/2012 05:10, Subodh Asthana wrote:
>>
>> Executing UNO Dispatcher in VBScript doesn't reflect any changes in ODS
>> file
>> http://stackoverflow.com/q/9562093/264668?sem=2
>>
>> Following is the code that I wrote to try formatting ODS using VBSript. It
>> runs without any error but it *does not reflect any change* in the ODS
>> file.
>>
>> Dim propertyset(0)
>> Dim arg()
>> Set oServiceManager = CreateObject("com.sun.star.ServiceManager")
>> Set oDesktop =
>> oServiceManager.createInstance("com.sun.star.frame.Desktop")
>> Set UnoObj =
>> oServiceManager.createInstance("com.sun.star.frame.DispatchHelper")
>> sFileName = "D:\Untitled 1.ods"
>> sFileName = Replace (sFileName, "\", "/")
>> sURL = "file:///"&  sFileName
>> Set oSpreadsheet = oDesktop.loadComponentFromURL(sURL, "_blank", 0,
>> arg)    'load existing spreadsheet
>>
>> set oSheet1 = oSpreadsheet.getSheets.getByName( "Sheet1" )
>> set document   = oSpreadsheet.CurrentController.Frame
>>
>> Set propertyset(0) = MakePropertyValue(oServiceManager, "ToPoint", "$A$1")
>> Call UnoObj.executeDispatch(document, ".uno:GoToCell", "", 0, propertyset)
>>
>> Set propertyset(0) = MakePropertyValue(oServiceManager,
>> "BackgroundColor", 16711680)
>> Call UnoObj.executeDispatch(document, ".uno:BackgroundColor", "", 0,
>> propertyset)
>> oSpreadsheet.Close(True)
>> set UnoObj = Nothing
>> set oSpreadsheet = Nothing
>> set oDesktop = Nothing
>> set oServiceManager = Nothing
>>
>> Function MakePropertyValue(oServiceManager, cName, uValue)
>>    Dim oStruct
>>    Set oStruct =
>> oServiceManager.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
>>    Set MakePropertyValue = oStruct
>> End Function
>>
>
>

Re: Executing UNO Dispatcher in VBScript doesn't reflect any changes in ODS file

Posted by TJ Frazier <tj...@cfl.rr.com>.
Try adding a Store request:
 > Call UnoObj.executeDispatch(document, ".uno:BackgroundColor", "", 0,
 > propertyset)
oSpreadsheet.Store()
 > oSpreadsheet.Close(True)
Close won't do that for you.
/tj/

On 3/5/2012 05:10, Subodh Asthana wrote:
> Executing UNO Dispatcher in VBScript doesn't reflect any changes in ODS file
> http://stackoverflow.com/q/9562093/264668?sem=2
>
> Following is the code that I wrote to try formatting ODS using VBSript. It
> runs without any error but it *does not reflect any change* in the ODS file.
>
> Dim propertyset(0)
> Dim arg()
> Set oServiceManager = CreateObject("com.sun.star.ServiceManager")
> Set oDesktop = oServiceManager.createInstance("com.sun.star.frame.Desktop")
> Set UnoObj = oServiceManager.createInstance("com.sun.star.frame.DispatchHelper")
> sFileName = "D:\Untitled 1.ods"
> sFileName = Replace (sFileName, "\", "/")
> sURL = "file:///"&  sFileName
> Set oSpreadsheet = oDesktop.loadComponentFromURL(sURL, "_blank", 0,
> arg)    'load existing spreadsheet
>
> set oSheet1 = oSpreadsheet.getSheets.getByName( "Sheet1" )
> set document   = oSpreadsheet.CurrentController.Frame
>
> Set propertyset(0) = MakePropertyValue(oServiceManager, "ToPoint", "$A$1")
> Call UnoObj.executeDispatch(document, ".uno:GoToCell", "", 0, propertyset)
>
> Set propertyset(0) = MakePropertyValue(oServiceManager,
> "BackgroundColor", 16711680)
> Call UnoObj.executeDispatch(document, ".uno:BackgroundColor", "", 0,
> propertyset)
> oSpreadsheet.Close(True)
> set UnoObj = Nothing
> set oSpreadsheet = Nothing
> set oDesktop = Nothing
> set oServiceManager = Nothing
>
> Function MakePropertyValue(oServiceManager, cName, uValue)
>     Dim oStruct
>     Set oStruct =
> oServiceManager.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
>     Set MakePropertyValue = oStruct
> End Function
>