I have a large project 4x per year. We can export the data we need to present to CSV, so opening that data in Calc and cleaning it up is no problem at all.
So now we have ~700-800 rows and only 2 columns to deal with.
What I want is to import that data into Impress, where each row will generate it’s own slide, following a predetermined layout or template.
I’ve tried convincing pi.ai and chatgpt to write some macros for me with no luck.
BASIC runtime error.
An exception occurred
Type: com.sun.star.lang.ServiceNotRegisteredException
Message: at /usr/src/debug/libreoffice-fresh/libreoffice-7.6.4.1/sd/source/ui/unoidl/unomodel.cxx:1060
IDK, it’s all foreign black magic to me…
Here’s the macro it generated, for context of course, because I’m not sure how useful it is in regards to the task at hand…
Sub ImportDataFromCalcToImpress
Dim oImpressDoc As Object
Dim oCalcDoc As Object
Dim oSheet As Object
Dim oRange As Object
Dim i As Integer
Dim slideIndex As Integer
' Open Impress document
oImpressDoc = StarDesktop.loadComponentFromURL("private:factory/simpress", "_blank", 0, Array())
' Open Calc document using direct method
oCalcDoc = StarDesktop.loadComponentFromURL("file:///home/bbbbbb/mydoc.ods", "_blank", 0, Array())
' Check if Calc document is loaded successfully
If Not IsNull(oCalcDoc) Then
' Attempt to get the Calc sheet with data
On Error Resume Next
oSheet = oCalcDoc.Sheets.getByName("Sheet1") 'Change "Sheet1" to your Calc sheet name
On Error GoTo 0
If Not IsNull(oSheet) Then
' Get the cell range with data
oRange = oSheet.getCellRangeByName("A2:B100") 'Change "A2:B100" to your desired range
' Loop through each row of data
For i = 0 To oRange.Rows.Count - 1
' Create a new slide for each row of data
slideIndex = oImpressDoc.createInstance("com.sun.star.presentation.Presentation").createInstance("com.sun.star.presentation.Slide")
' Import Lot # and Lot Title from Calc to Impress text boxes
oImpressDoc.getDrawPages().insertByIndex(oImpressDoc.getDrawPages().Count, oImpressDoc.createInstance("com.sun.star.drawing.GenericDrawPage"))
oImpressDoc.getDrawPages().getByIndex(oImpressDoc.getDrawPages().Count - 1).setName("Slide " & slideIndex + 1)
oImpressDoc.getDrawPages().getByIndex(oImpressDoc.getDrawPages().Count - 1).add(oImpressDoc.createInstance("com.sun.star.drawing.TextShape"))
oImpressDoc.getDrawPages().getByIndex(oImpressDoc.getDrawPages().Count - 1).getByIndex(0).setPosition(CreateUnoStruct("com.sun.star.awt.Point", 500, 500))
oImpressDoc.getDrawPages().getByIndex(oImpressDoc.getDrawPages().Count - 1).getByIndex(0).setSize(CreateUnoStruct("com.sun.star.awt.Size", 2000, 500))
oImpressDoc.getDrawPages().getByIndex(oImpressDoc.getDrawPages().Count - 1).getByIndex(0).setText(oRange.getCellByPosition(0, i).String & vbCrLf & oRange.getCellByPosition(1, i).String)
Next i
Else
MsgBox("Sheet 'Sheet1' not found in Calc document.")
End If
' Close Calc document
oCalcDoc.close(True)
Else
MsgBox("Calc document not loaded successfully.")
End If
End Sub
¯\_(ツ)_/¯
TY <3