How to copy TextTable from one doc to another with Basic

I’m using LibreOffice 24.2.6.2 (X86_64) on Ubuntu 22.04.5 LTS

I’d like to copy a table from one doc to another but this approach isn’t working. It errors on the last line.

	strPath = ConvertToUrl("/home/wrg/Documents/projects/MT script test doc5.odt")
	oPTGuideDoc = StarDesktop.loadComponentFromURL(strPath, "_default", 0, args())
		
	tables = oPTGuideDoc.TextTables
	oBlankSkillTable = tables.getByName("BlankSkillTable")
	
	' Create new doc
	oNewDoc = StarDesktop.loadComponentFromURL("private:factory/swriter","_default", 0, args())
	'Goto the end of the doc
	oInsertPoint = oNewDoc.Text.getEnd()
	'Add table from the first doc to this new doc
	oInsertPoint.getText().insertTextContent(oInsertPoint, oBlankSkillTable, False)

How can I do that?

Also, can I add the same table twice and merge the two? It may make more sense looking at the table so it’s attached here.
MT script test doc5.odt (27.7 KB)

Again? Once more?

1 Like

Ok, getTransferable() and insertTransferable() how about the merge table part, any idea there?

Why not record this action using a macro recorder?

...
    ' Paste the copied table
	oTargetDoc.getCurrentController().insertTransferable(oFrame1.Controller.getTransferable())
	oTargetDoc.getCurrentController().insertTransferable(oFrame1.Controller.getTransferable())
    ' Close the source document without saving changes
    oSourceDoc.close(False)
	' Join last two tables
    oCursor = oTargetDoc.getCurrentController().getViewCursor()
    oCursor.goUp(1, True)
    oCursor.goRight(1, False)
    oCursor.goLeft(1, False)
    With createUnoService("com.sun.star.frame.DispatchHelper")
	    .executeDispatch(oTargetDoc.getCurrentController().getFrame(), ".uno:Delete", "", 0, Array())
		.executeDispatch(oTargetDoc.getCurrentController().getFrame(), ".uno:MergeTable", "", 0, Array())
    End With 
 ...