How to copy table context to another table

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
zenira
Posts: 88
Joined: Sun May 11, 2014 11:24 am

How to copy table context to another table

Post by zenira »

hi friends
I want to copy all table context into other table. Table has paragragh and numering context. I always get same message
5gD31z.jpg
V0rGoP.jpg

Code: Select all

Option Explicit
dim Table1,Table2,Table1cell,Table2cell as object

Sub Main

Table1=ThisComponent.TextTables.getByName("Table1")
Table1Cell=Table1.getCellByName("A1")
Table2=ThisComponent.TextTables.getByName("Table2")
Table2Cell=Table2.getCellByName("A1")

dim Enum1,Cursor as object
dim Para as object 

Enum1=Table1Cell.createEnumeration 
Cursor=Table2Cell.createTextCursor

while Enum1.hasMoreElements
	Para=Enum1.NextElement()
	Table2Cell.insertTextContent(Cursor.getEnd(),Para.getText, False) 
wend

End Sub
thanks for your advice
Attachments
CopyTableContext.odt
example file
(14.17 KiB) Downloaded 149 times
LibreOffice 4.1.0.4 on Windows 7
zenira
Posts: 88
Joined: Sun May 11, 2014 11:24 am

Re: How to copy table context to another table

Post by zenira »

I can get string and paste it correctly but it destroys the format

Code: Select all

Table2Cell.insertTextContent(Cursor.getEnd(),Para.getString, False)
LibreOffice 4.1.0.4 on Windows 7
UnklDonald418
Volunteer
Posts: 1544
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: How to copy table context to another table

Post by UnklDonald418 »

Have you looked at Andrew Pitonyak's examples in his book “OpenOffice.org Macros Explained”?
Listing 381 copies and pastes a named Writer table using the clipboard, so all the formatting is preserved.
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
Post Reply