[Solved] Problem on VB.net and chart

Java, C++, C#, Delphi... - Using the UNO bridges
Post Reply
keosge
Posts: 5
Joined: Fri Dec 14, 2012 12:50 am

[Solved] Problem on VB.net and chart

Post by keosge »

I'm trying to add a chart to a calc new file, but when i try to do, it give me this error: [automation bridge] unexpected exception in UnoConversionUtilities<T>::variantToAny !
at line Charts.addNewByName("MyChart", Rect, RangeAddress, False, False).

this is the code

Code: Select all

        Dim Doc As Object
        Dim Charts As Object
        Dim Chart As Object
        Dim Rect As New unoidl.com.sun.star.awt.Rectangle
        Dim RangeAddress(0) As Object

        Url = "private:factory/scalc"

        oSM = CreateObject("com.sun.star.ServiceManager")
        odp = oSM.createInstance("com.sun.star.frame.Desktop")
        odc = odp.loadComponentFromURL(Url, "_blank", 0, aNoArgs)
        oss = odc.Sheets(0)
        os = oss.getByIndex(0)

        Dim OpenPar(1) As Object

        dispatch = oSM.createInstance("com.sun.star.frame.DispatchHelper")



        'RangeAddress(0) = New unoidl.com.sun.star.table.CellRangeAddress
        RangeAddress(0) = oSM.Bridge_GetStruct("com.sun.star.table.CellRangeAddress")
        Charts = os.charts
        Rect.X = 8000
        Rect.Y = 1000
        Rect.Width = 10000
        Rect.Height = 7000
        RangeAddress(0).Sheet = 0
        RangeAddress(0).StartColumn = 1
        RangeAddress(0).StartRow = 3
        RangeAddress(0).EndColumn = 1
        RangeAddress(0).EndRow = 13



        Dim oMRI As Object
        oMRI = oSM.createInstance("mytools.Mri")
        oMRI.inspect(Charts)

        Charts.addNewByName("MyChart", Rect, RangeAddress, False, False)
can some body help me?
Last edited by keosge on Sat Dec 15, 2012 1:15 am, edited 1 time in total.
OpenOffice 3.4 on Win7
User avatar
Charlie Young
Volunteer
Posts: 1559
Joined: Fri May 14, 2010 1:07 am

Re: Problem on VB.net and chart

Post by Charlie Young »

I think it doesn't like

Code: Select all

Dim Rect As New unoidl.com.sun.star.awt.Rectangle
though there may be some trick for getting that to work.

You should be able to fix it with

Code: Select all

Dim Rect As Object

...

Rect = oSM.Bridge_GetStruct("com.sun.star.awt.Rectangle")
Apache OpenOffice 4.1.1
Windows XP
FJCC
Moderator
Posts: 9278
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Problem on VB.net and chart

Post by FJCC »

Charlie is correct. This works for me.

Code: Select all

Sub MakeChart()
Dim Doc As Object
        Dim Charts As Object
        Dim Chart As Object
        Dim RangeAddress(0) As Object

        URL = "private:factory/scalc"

        Set oSM = CreateObject("com.sun.star.ServiceManager")
        Set odp = oSM.createInstance("com.sun.star.frame.Desktop")
        Set odc = odp.loadComponentFromURL(URL, "_blank", 0, Array())
        Set oss = odc.Sheets(0)
        Set os = oss.getByIndex(0)

        Dim OpenPar(1) As Object
        
        Set Rect = oSM.Bridge_GetStruct("com.sun.star.awt.Rectangle")

        Set RangeAddress(0) = oSM.Bridge_GetStruct("com.sun.star.table.CellRangeAddress")
        Set Charts = os.Charts
        Rect.X = 8000
        Rect.Y = 1000
        Rect.Width = 10000
        Rect.Height = 7000
        RangeAddress(0).Sheet = 0
        RangeAddress(0).StartColumn = 1
        RangeAddress(0).StartRow = 3
        RangeAddress(0).EndColumn = 1
        RangeAddress(0).EndRow = 13

        'Dim oMRI As Object
        'oMRI = oSM.createInstance("mytools.Mri")
        ' oMRI.Inspect (Charts)

        Charts.addNewByName "MyChart", Rect, RangeAddress, False, False
End Sub
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
keosge
Posts: 5
Joined: Fri Dec 14, 2012 12:50 am

Re: Problem on VB.net and chart

Post by keosge »

Thank a lot,

the correct it's that

Rect = oSM.Bridge_GetStruct("com.sun.star.awt.Rectangle")

i solved it
OpenOffice 3.4 on Win7
Post Reply