How to Select and Copy Specific Text from Template A to a new Template B in LibreOffice Writer?

I have a template A document that people use to fill out information about new projects. Some parts of this information should also be used in a template B document. How can I select and copy specific information in a table (see screenshot) and then paste it into a new template B document in a specific location?

So far, code found from this post:

Sub findCopyPaste
	dim oDoc as object, oDesc as object, oFound as object, data as object, oDoc2 as object
	oDoc=ThisComponent
	oDesc=oDoc.createSearchDescriptor
	with oDesc
		.SearchString="[:print:]{1,100} / [:digit:]{1,100} / [:digit:]{1,4}"
		.SearchRegularExpression=true
	end with
	oFound=oDoc.findFirst(oDesc)
	if NOT isNull(oFound) then 'something is found
		oDoc.CurrentController.Select(oFound) 'Select
		data=oDoc.currentController.getTransferable 'Copy
		oDoc2=StarDesktop.LoadComponentFromUrl("private:factory/swriter", "_blank", 0, array()) 'new document
		oDoc2.CurrentController.insertTransferable(data) 'Paste
	end if
End Sub

What do you need to copy? Whole table? Or you need find something in some line and copy for example two lines?
For example you need to find and copy whole table where owner is Jane?
It is possible to select the cells in table with TableCursor.

Your ODT with example would be better.

1 Like