[Solved] Cannot change textflow of table within subdocument

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
spun69
Posts: 3
Joined: Sat Jan 27, 2018 1:16 am

[Solved] Cannot change textflow of table within subdocument

Post by spun69 »

Hello
I need to create a document consisting of some header text, then the output of two reports generated from Oracle ReportBuilder (RB) . I am currently using a Writer master document for this, but seeing the same behavior with simple document importing the same subdocuments. I can load the two subdocuments successfully with silent update to refresh content. My problem is the tables generated in RB have 'break before' textflow attribute, so there is a page break before each subdocument; cannot find anyway to change this in RB. I want to change the tables BreakType to NONE.

The code below tries to do this, but does not seem to be working as the final document still has the page breaks. I have tried a number of approaches without success. Using debugger, I have verified the list/order of tables to confirm the correct objects are used. In fact, if I assign breaktype value other than NONE, Writer does show change in textflow.

Note using Writer interactively, I can easily change the document to remove the page break in the Table properties textflow tab, but need this automated via macro. Any suggestions?

Code: Select all

'Routine to repair text flow post merge
Sub PostMergeRepair()
	Dim odReport, oController, oTables, oTable

    'Create objects of required type
	Set odReport = createunoservice("com.sun.star.text.TextDocument")
	Set oTables  = createunoservice("com.sun.star.text.TextTables")
	Set oTable   = createunoservice("com.sun.star.text.TextTable")

	'MASTER document with two subdocuments
	Set odReport = ThisComponent
	Set oTables = odReport.getTextTables()

	'Set textflow on ingested subdocuments
    Set oTable  =  odReport.getTextTables().getByIndex(0)
    oTable.BreakType = com.sun.star.style.BreakType.NONE

    Set oTable  =  odReport.getTextTables().getByIndex(1)
    oTable.BreakType = com.sun.star.style.BreakType.NONE
	
End Sub
Last edited by robleyd on Sun Jan 28, 2018 1:08 am, edited 1 time in total.
Reason: Tagged [Solved] [robleyd, Moderator]
Apache OpenOffice 4.1.5
Windows 10 Pro [64bit]
John_Ha
Volunteer
Posts: 9583
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Cannot change textflow of table within subdocument

Post by John_Ha »

Welcome to the (wrong) forum.

I say wrong as there is a Macros and UNO API forum where searching with table breaktype found Modify paragraph properties

Try recording a macro while doing it manually - if it works, use that code.

Andrew Pitoynak's Useful Macro Information for OpenOffice.org at http://www.pitonyak.org/oo.php is an excellent reference for macros.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
John_Ha
Volunteer
Posts: 9583
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Cannot change textflow of table within subdocument

Post by John_Ha »

Does Text Documents: More Than Just Text, which deals with programming tables, help? Or interface XTextContent which "enables objects to be inserted into a text and to provide their location in a text once they are inserted into it."

Could you insert each table inside a frame which will nullify the effect of the new page you cannot remove?
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
spun69
Posts: 3
Joined: Sat Jan 27, 2018 1:16 am

Re: Cannot change textflow of table within subdocument

Post by spun69 »

John_Ha wrote:Welcome to the (wrong) forum.

I say wrong as there is a Macros and UNO API forum where searching with table breaktype found Modify paragraph properties

Try recording a macro while doing it manually - if it works, use that code.

Andrew Pitoynak's Useful Macro Information for OpenOffice.org at http://www.pitonyak.org/oo.php is an excellent reference for macros.
Thank you for the prompt reply and the guidance. I will try out your suggestions and get back...
Apache OpenOffice 4.1.5
Windows 10 Pro [64bit]
spun69
Posts: 3
Joined: Sat Jan 27, 2018 1:16 am

Re: Cannot change textflow of table within subdocument

Post by spun69 »

After reading some of the references, I reworked my code to make use of TextFrames and Bookmarks. Now I generate the report, extract required table(s), then paste into the output document at a bookmark location within a frame. This does exactly what I need. Thanks again for the support!! :super:
Working code below.

Code: Select all

'Routine to import block from generated report
Sub InsertReportBlock(odOutput As Object, sReportName As String, sTables As Object, sBkmrkName As String )
	Dim odReport, oController, oTable, oInCursor, oOutCursor, oBlock, oBookmark
	Dim pvArgs(2) As New com.sun.star.beans.PropertyValue
	Dim i
	
	Set odReport = createunoservice("com.sun.star.text.TextDocument")
	Set oTable   = createunoservice("com.sun.star.text.TextTable")
	Set oController = CurrentDb.Document.CurrentController

	'Generate reports for reservation details & invoice
	pvArgs(0).Name  = "Hidden" : pvArgs(0).Value = True
	Set odReport  = oController.loadComponentWithArguments(com.sun.star.sdb.application.DatabaseObject.REPORT, sReportName, acViewNormal, pvArgs)

	Set oInCursor  = odReport.CurrentController.getViewCursor()
	Set oOutCursor = odOutput.CurrentController.getViewCursor()
	Set oBookmark  = odOutput.getBookmarks().getByName(sBkmrkName)

	'Loop over list of table names
	For i = LBound(sTables) To UBound(sTables)
		'Copy report content
		Set oTable = odReport.getTextTables().getByName(sTables(i)) 
		odReport.CurrentController.select(oTable)  
	 	oInCursor.gotoEnd(True)  'Move to the end of the current cell.
	  	oInCursor.gotoEnd(True)  'Move to the end of the table.  
	  	Set oBlock = odReport.CurrentController.getTransferable()  

		'Paste at bookmark 
  		oOutCursor.gotoRange(oBookmark.getAnchor(), False)  'Move the cursor to bookmark location
  		odOutput.CurrentController.insertTransferable(oBlock)
  	Next
  	
Exit_Function:
	odReport.dispose()

End Sub
Apache OpenOffice 4.1.5
Windows 10 Pro [64bit]
Post Reply