Extract all chart data to sheets LibreOffice Writer macro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 sasha.libreoffice@gmail.com | |
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 | |
EndIf | |
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 = m.data.rowDescriptions | |
ColumnTitles = m.data.columnDescriptions | |
DiagramData = m.data.data | |
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