Save As - ooBasic - Impress with charts

Creating a macro - Writing a Script - Using the API

Save As - ooBasic - Impress with charts

Postby whitav8 » Sat Dec 15, 2012 7:37 pm

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
dhw
OpenOffice 3.1 on Windows 7
whitav8
 
Posts: 8
Joined: Wed Oct 03, 2012 7:27 pm

Re: Save As - ooBasic - Impress with charts

Postby Charlie Young » Sat Dec 15, 2012 9:49 pm

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   Expand viewCollapse view
   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.
Apache OpenOffice 4.1.1
Windows XP
User avatar
Charlie Young
Volunteer
 
Posts: 1559
Joined: Fri May 14, 2010 1:07 am

Re: Save As - ooBasic - Impress with charts

Postby polusha » Mon Feb 18, 2019 8:25 am

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.
OpenOffice 3.1 ?? Windows Vista / NeoOffice 2.2.3 ?? MacOS 10.4 / OpenOffice 2.4 ?? Ubuntu 9.04
polusha
 
Posts: 9
Joined: Sun Feb 17, 2019 8:35 pm

Re: Save As - ooBasic - Impress with charts

Postby Zizi64 » Mon Feb 18, 2019 8:51 am

Tibor Kovacs, Hungary; LO4.4.7, LO6.1.5 on Win7-10 x64Prof.
PortableApps, winPenPack: LO3.3.0-6.2.2; AOO4.1.5
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 7900
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Save As - ooBasic - Impress with charts

Postby polusha » Mon Feb 18, 2019 9:19 am

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.
OpenOffice 3.1 ?? Windows Vista / NeoOffice 2.2.3 ?? MacOS 10.4 / OpenOffice 2.4 ?? Ubuntu 9.04
polusha
 
Posts: 9
Joined: Sun Feb 17, 2019 8:35 pm

Re: Save As - ooBasic - Impress with charts

Postby Zizi64 » Mon Feb 18, 2019 10:24 am

How to get a chart in the Calc by macro:

viewtopic.php?f=45&t=78049
Tibor Kovacs, Hungary; LO4.4.7, LO6.1.5 on Win7-10 x64Prof.
PortableApps, winPenPack: LO3.3.0-6.2.2; AOO4.1.5
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 7900
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Save As - ooBasic - Impress with charts

Postby polusha » Mon Feb 18, 2019 10:36 am

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.
OpenOffice 3.1 ?? Windows Vista / NeoOffice 2.2.3 ?? MacOS 10.4 / OpenOffice 2.4 ?? Ubuntu 9.04
polusha
 
Posts: 9
Joined: Sun Feb 17, 2019 8:35 pm

Re: Save As - ooBasic - Impress with charts

Postby RoryOF » Mon Feb 18, 2019 10:44 am

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.
Apache OpenOffice 4.1.6 on Xubuntu 18.04.2 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 28738
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Save As - ooBasic - Impress with charts

Postby polusha » Mon Feb 18, 2019 11:44 am

It is necessary to save the diagram
OpenOffice 3.1 ?? Windows Vista / NeoOffice 2.2.3 ?? MacOS 10.4 / OpenOffice 2.4 ?? Ubuntu 9.04
polusha
 
Posts: 9
Joined: Sun Feb 17, 2019 8:35 pm

Re: Save As - ooBasic - Impress with charts

Postby polusha » Mon Feb 18, 2019 6:54 pm

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   Expand viewCollapse view
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?
OpenOffice 3.1 ?? Windows Vista / NeoOffice 2.2.3 ?? MacOS 10.4 / OpenOffice 2.4 ?? Ubuntu 9.04
polusha
 
Posts: 9
Joined: Sun Feb 17, 2019 8:35 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 2 guests