Skip to content

Instantly share code, notes, and snippets.

Created March 4, 2021 22:36
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Extract all chart data to sheets LibreOffice Writer macro
REM ***** BASIC *****
'Extract data from all charts in document
'Will open all charts as new Calc spreadsheets
'and you can edit them and save them there.
'Based on ExtractDiagramToSheet by
Sub ExtractAllDiagramsToSheets
'On error resume next
Dim embObjects as Object
doc = ThisComponent
embObjects = doc.embeddedObjects
'Loop over all embedded objects
For chartNumber = 0 to embObjects.Count - 1
o = embObjects.getByIndex(chartNumber)
oExt = o.ExtendedControlOverEmbeddedObject
m = oExt.component
If isEmpty(m) Then
MsgBox ("Empty diagram", "Wrong object")
Exit Sub ' it is not a chart selected
oURL = "private:factory/scalc"
oDoc = starDeskTop.loadComponentFromURL(oURL, "_blank", 0, Array() )
oSheet = oDoc.Sheets(0)
'adding titles and names
oSheet.Name = "Extracted diagram"
oSheet.getCellByPosition(0, 0).string = m.title.string
oSheet.getCellByPosition(0, 1).string = m.subtitle.string
'Extracting data into variables
RowTitles =
ColumnTitles =
DiagramData =
AmountOfRows = UBound(RowTitles) ' both zero-bazed
AmountOfColumns = UBound(ColumnTitles)
'titles of columns and rows
For i = 0 to AmountOfRows : oSheet.getCellByPosition(0, i+3).string = RowTitles(i) : Next i
For i = 0 to AmountOfColumns : oSheet.getCellByPosition(i+1, 2).string = ColumnTitles(i) : Next i
'Data of chart itself
For y = 0 to AmountOfRows
For x = 0 to AmountOfColumns
oSheet.getCellByPosition(x+1, y+3).value = DiagramData(y)(x)
Next x
Next y
Next chartNumber
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment