Page 1 of 1

Save As - ooBasic - Impress with charts

Posted: Sat Dec 15, 2012 7:37 pm
by whitav8
I am trying to save (as) an Impress Presentation that was created with charts copied from a spreadsheet. Now I want to save (as) it preferably as a PPT but ODP would be OK.
____________________________________________________________________________________________
oSheet = ThisComponent.Sheets.getByIndex(0)
oDP = oSheet.DrawPage
oChartShape = oDP.getByIndex(0) 'get the chart

' URL = convertToURL("C:\PasteTarget.odp")
oPresentation = StarDesktop.loadComponentFromURL(URL, "_blank", 0, Array())

MyRect = oPresentation.createInstance("com.sun.star.drawing.OLE2Shape")
MyRect.CLSID = "12dcae26-281f-416f-a234-c3086127382e" 'Make the shape a chart

oDrawPage = oPresentation.DrawPages.getByIndex(0) 'Get the Draw page of the first slide
REM add the rect to the slide
oDrawPage.add(MyRect)

REM Do the actual copy of the chart
MyRect.Model.Diagram = oChartShape.Model.Diagram

______________________________________________________________________________________________________

NOW HOW Do I do a SaveAS??? I tried the following but I get an error with the storeAsURL (I tried StoreToURL as well)
___________________________________________________________________________________________________________
sPath = "E:\Flyit_FlightTest\Logs\Flyit_121412\"
sFileName = "MyTest.odp"
sSaveToURL = ConvertToURL(sPath & sFileName)
thisComponent.storeAsUrl(sSaveToURL, Array(MakePropertyValue("FilterName", "ODF Presentation")))
'StoreAs/ToURL?
___________________________________________________________________________________________________________
Function MakePropertyValue(Optional sName As String, Optional sValue) As com.sun.star.beans.PropertyValue
'-------------------------------------------------------------------
' Create and return a new com.sun.star.beans.PropertyValue
'-------------------------------------------------------------------
Dim oPropertyValue As New com.sun.star.beans.PropertyValue


If Not IsMissing(sName) Then
oPropertyValue.Name = sName
EndIf

If Not IsMissing(sValue) Then
oPropertyValue.Value = sValue
EndIf

MakePropertyValue() = oPropertyValue

End Function

Re: Save As - ooBasic - Impress with charts

Posted: Sat Dec 15, 2012 9:49 pm
by Charlie Young
whitav8 wrote:I am trying to save (as) an Impress Presentation that was created with charts copied from a spreadsheet. Now I want to save (as) it preferably as a PPT but ODP would be OK.

Code: Select all

   thisComponent.storeAsUrl(sSaveToURL, Array(MakePropertyValue("FilterName", "ODF Presentation")))
I don't think "ODF Presentation" is a valid FilterName. Try "impress8" for .odp, or "MS PowerPoint 97" for PowerPoint, though there are also a number of possibilities for XML and such.

Re: Save As - ooBasic - Impress with charts

Posted: Mon Feb 18, 2019 8:25 am
by polusha
Did you manage to copy the chart from calc to impress?
Could you show the code. Thank you in advance. Your code doesn't work for me.

Re: Save As - ooBasic - Impress with charts

Posted: Mon Feb 18, 2019 8:51 am
by Zizi64

Re: Save As - ooBasic - Impress with charts

Posted: Mon Feb 18, 2019 9:19 am
by polusha
The links describe the ability to save the file in a different format.
But I need to copy the chart from calc to impress.
That is, not the whole file, only one diagram.

And unfortunately I don’t understand how to do it. = (

Perhaps you could give an example. Thank you in advance!

PS Sorry for my bad english.

Re: Save As - ooBasic - Impress with charts

Posted: Mon Feb 18, 2019 10:24 am
by Zizi64
How to get a chart in the Calc by macro:

viewtopic.php?f=45&t=78049

Re: Save As - ooBasic - Impress with charts

Posted: Mon Feb 18, 2019 10:36 am
by polusha
I can get a graph from a calc sheet and I can also get a slide where I want to insert it
But this does not work by simple =.
I guess it should work through ".uno: Paste" / ".uno: Paste" but I still can't do it. The graph does not appear.
Here (viewtopic.php?f=20&t=97044) the topic is where I ask this question and there is code to copy the slide from one ODP to another

But when I try to copy a diagram, nothing works.

Re: Save As - ooBasic - Impress with charts

Posted: Mon Feb 18, 2019 10:44 am
by RoryOF
A quick workaround would be to take a screenshot of the chart or diagram, then insert that into the Impress file. Of course that is a static image and would not reflect the current state of the data generating the chart.

Re: Save As - ooBasic - Impress with charts

Posted: Mon Feb 18, 2019 11:44 am
by polusha
It is necessary to save the diagram

Re: Save As - ooBasic - Impress with charts

Posted: Mon Feb 18, 2019 6:54 pm
by polusha
Task:
1) I need from 1 calc sheet to copy 1 graph (first) and paste it on the 1st slide. Impress

How I try to do it

Code: Select all

import sys
import os
import time
import uno
import pyuno

def mergeFromExcelURL():
    localContext = uno.getComponentContext()
    resolver = localContext.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", localContext)
    ctx = resolver.resolve("uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext")
    desk = ctx.ServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", ctx)

    # ODP
    doc1 = desk.loadComponentFromURL(fileNameToUrl('default.odp'), "_blank", 0, ())
    dispatcher = ctx.ServiceManager.createInstanceWithContext("com.sun.star.frame.DispatchHelper", ctx)

    DrawPageODP = doc1.DrawPages.getByIndex(0)
    ShapeODP = DrawPageODP.getByIndex(0)

    ctr1 = doc1.getCurrentController()
    frame1 = ctr1.Frame

    #ODS
    doc2 = desk.loadComponentFromURL(fileNameToUrl('bubble.ods'), "_blank", 0, ())
    ctr2 = doc2.getCurrentController()
    frame2 = ctr2.Frame

    dispatcher.executeDispatch(frame1, ".uno:DiaMode", "", 0, ())
    dispatcher.executeDispatch(frame2, ".uno:DiaMode", "", 0, ())

    ChartSheet = doc2.Sheets.getByName('Chart')
    DrawPage = ChartSheet.DrawPage
    ChartShape = DrawPage.getByIndex(0)
    Diagram = ChartShape.Model.Diagram
    EmbObj = ChartShape.EmbeddedObject


    #SElect2
    ctr2.select(ChartShape) # This is not true most likely. probably it is necessary to choose a diagram, but it does not work. ????????????????????
    dispatcher.executeDispatch(frame2, ".uno:Copy", "", 0, ())

    # SElect1
    ctr1.setCurrentPage(DrawPageODP) # What is there to choose? ????????????????????
    dispatcher.executeDispatch(frame1, ".uno:Paste", "", 0, ())

    dispatcher.executeDispatch(frame1, ".uno:DrawingMode", "", 0, ()) #?????????????????????????

    outfile = "output.odp"
    doc1.storeAsURL(fileNameToUrl(outfile), ())
    doc1.close(False)
    doc2.close(True)
Can you tell me in the right direction?