I have given the following Macro starbase code (see attachment)
It tries to copy a chart from Libre Calc to Libre writer.
However, it says that no chart exists with such name.
(see my other post - cviewtopic.php?f=9&t=106011 )
Code: Select all
Sub CopyChartToWriter 'copy the chart from the Calc sheet to the Writer document
dim oDoc as object, oSheet as object, vChart as variant, data as object
oDoc=ThisComponent
oSheet=oDoc.Sheets.getByName("Graph_stat") 'sheet with chart
vChart=getChart("stat1", oSheet) 'the chart named for example by right-mouse and Name, or from menu Format/ Name
print vChart
if NOT isObject(vChart) then 'the chart doesn't exists
msgbox vChart & " - doesn't exists!"
exit sub
end if
oDoc.CurrentController.ActiveSheet=oSheet
oDoc.CurrentController.Select(vChart)
data=oDoc.CurrentController.getTransferable() 'LibreOffice internal Ctrl+C
rem Writer document
dim oDocWriter as object, sUrl$, oVCur as object
sUrl="private:factory/swriter" 'new writer document
'sUrl=ConvertToUrl("d:/documents/example.odt") 'or your writer file
oDocWriter=StarDesktop.LoadComponentFromUrl(sURL, "_blank", 0, array()) 'open Writer document
rem paste chart to the end of the visible cursor
oVCur=oDocWriter.CurrentController.getViewCursor 'visible cursor
oVCur.collapseToEnd
oDocWriter.CurrentController.Select(oVCur) 'select visible cursor
oDocWriter.CurrentController.insertTransferable(data) 'Libre internal Ctrl+V
End Sub
Function getChart(s$, oSheet as object) as variant 'returns the chart as object (if chart exists); or returns the chart name as string
dim i&, o as object
for i=0 to oSheet.DrawPage.Count-1
o=oSheet.DrawPage.getByIndex(i)
'xray oSheet.DrawPage
if o.PersistName=s then 'the needy property from the xray on previous line -> PersistName is setted from the function CreateCalcWithSimpleChart
getChart=o 'return the chart as object
exit function
end if
next i
getChart=s 'return the name of the chart as string
End Function