Howto get TextTable object, without getViewCursor()

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
arfgh
Posts: 566
Joined: Tue Mar 05, 2013 6:44 pm

Howto get TextTable object, without getViewCursor()

Post by arfgh »

hey there friends.
I know how to get the object TextTable from the cursor view, but now i want to reach the TextTable object of a table from out ot the tableGrid, for example running a macro from a label, that means, with no getViewCursor() method. I use that way in the report document tables, but now the intention is to do the same with a tableGrid control in the base form document.... surely they work diferent...

What i intent is to get all the data from 2 columns on the tablegrid to filter the form with the data.

Code: Select all

	cursor = view.getViewCursor()
	table = cursor.TextTable
   print table.rows.getCount()
At the moment i was unable to do it, and i dont understand why...

help
Last edited by arfgh on Tue Oct 30, 2018 2:54 pm, edited 2 times in total.
OpenOffice last version | Mageia Linux x64 | Ubuntu Linux | Windows 8.1 Enterprise x64 | Java last version
arfgh
Posts: 566
Joined: Tue Mar 05, 2013 6:44 pm

Re: Howto get TextTable object, without getViewCursor()

Post by arfgh »

Calling Mr. Villeroy

I used the getViewCursor() method in a report, and now i am in a base form. For sure the table in reports dont works by same way than the tablegrid control.....
OpenOffice last version | Mageia Linux x64 | Ubuntu Linux | Windows 8.1 Enterprise x64 | Java last version
User avatar
Lupp
Volunteer
Posts: 3542
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: Howto get TextTable object, without getViewCursor()

Post by Lupp »

I'm not sure if I understand correctly. I assume now you are talking of a TextTable being content (in one or another way) of a text document created with Writer. There may be form elements or not.

All the TextTables of a Writer document are know to one container. Having the document object, say oDoc, you can get this container by
oTTables = oDoc.GetTextTables() e.g.
Your specific table you should ask for its name or you can assign a (unique) chosen name to it (From the UI: Open the table properties dialogue.)
Then you can acces the object by
myTable = oTTables.GetByName(myTableName)
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
arfgh
Posts: 566
Joined: Tue Mar 05, 2013 6:44 pm

Re: Howto get TextTable object, without getViewCursor()

Post by arfgh »

^^ no.

I used TextTable object to use the cell methods to acess data and move through the cells. I did that in tables into Base reports thx to the getViewCursor() just clicking on some cell and obtaining by that way the access to the object TextTable.

I know that in a form document we can access the result set from the subform, and by some more limited way.... from the own tablegrid control.
But i am not sure if the object TextTable is also present on the form document...
OpenOffice last version | Mageia Linux x64 | Ubuntu Linux | Windows 8.1 Enterprise x64 | Java last version
User avatar
Lupp
Volunteer
Posts: 3542
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: Howto get TextTable object, without getViewCursor()

Post by Lupp »

What objet is your TextTable inserted to? I only know TextTables inserted as TextContent into any text object being directly (BodyText) or indirectly (that's .Text of a frame or of a cell of another table probably) content of a text document. The API documentation doesn't tell ma anything about TextTable objects not included under the terms I already listed.

Any TextTable should be able to create a TableCursor using .CreateCursorByCellName which you can use to roam in the table. First of all you need a grip on the table itself. You can get it the way I described earlier.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
arfgh
Posts: 566
Joined: Tue Mar 05, 2013 6:44 pm

Re: Howto get TextTable object, without getViewCursor()

Post by arfgh »

I assume that is an object to access the table cells content in the base reports. Let me show you a piece of code ok ?

Code: Select all

Sub HyperLinkReportColumn()
	dim form as object
	dim view as object, table as object, cursor as object
	dim item as string, dest as string, filter as string
	dim cellsN as object, cellsS as object, dataN(), dataS(), x as integer, y as integer
    form = ThisComponent.drawpage.forms(1)
    dest = form.getByIndex(0).tag
    view = ThisComponent.getCurrentController()
	cursor = view.getViewCursor()
	table = cursor.TextTable
	if dest = "XX" then
		cellsN = table.getCellRangeByName("B2:B" & table.rows.getcount & "")
		cellsS = table.getCellRangeByName("F2:F" & table.rows.getcount & "")
	elseif dest = "YY" then
		cellsN = table.getCellRangeByName("B2:B" & table.rows.getcount & "")	
	end if
	cellsN.setPropertyValue("BackColor", RGB(255, 255, 0))
    dataN = cellsN.getDataArray()
    dim RangeDataN(UBound(dataN),UBound(dataN)) as string
    for x = 0 To UBound(dataN)
    	for y = 0 to UBound(dataN(x))
        	RangeDataN(x,y) = dataN(x)(y)
        	filter = filter & "" & chr(34) & item & chr(34) & " = '" & RangeDataN(x,y) & "'"
        	if dest = "Juegos" or dest = "Accesorios" then
        		RangeDataS(x,y) = dataS(x)(y)        	
        		filter = filter & " and ""Sistema"" = '" & RangeDataS(x,y) & "' or "
        	else 
        		filter = filter & " or "
        	end if
    	next 	
    next
End Sub

I want to access the tablegrid control content in a base form document, using the showing objects and methods in the up code.
Like i said i know that we can access the result set on the subform that contains the tablegrid control, but that way to access is slow, we have to loop each result. Also wanted to know if some of ppl here tested to access the own datagrid control content instead of the subform result set, with the intention to see if is faster...
OpenOffice last version | Mageia Linux x64 | Ubuntu Linux | Windows 8.1 Enterprise x64 | Java last version
arfgh
Posts: 566
Joined: Tue Mar 05, 2013 6:44 pm

Re: Howto get TextTable object, without getViewCursor()

Post by arfgh »

anybody ?
OpenOffice last version | Mageia Linux x64 | Ubuntu Linux | Windows 8.1 Enterprise x64 | Java last version
RPG
Volunteer
Posts: 2250
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: Howto get TextTable object, without getViewCursor()

Post by RPG »

This answer assumed the question is about a grid-control in a data-form and not about a table in a writer document.

A grid control in a data-form does not have a viewcursor.

You see in a grid control more records but there is only one active record.

As far I understand: what you want is not possible. Maybe it is possible when you have clear under-standing of the module com.sun.star.awt. But that is a real complex module. I do not understand it. In com.sun.star.awt is a sub module special for gridcontrols: even difficult.
arfgh wrote:I want to access the tablegrid control content in a base form document, using the showing objects and methods in the up code.
Like i said i know that we can access the result set on the subform that contains the tablegrid control, but that way to access is slow, we have to loop each result.
I think you have to learn for a better understanding of the normal working of OOo. Most user macros makes it even more slower then faster. You must filter your data with SQL code and not with macros.

Romke
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
arfgh
Posts: 566
Joined: Tue Mar 05, 2013 6:44 pm

Re: Howto get TextTable object, without getViewCursor()

Post by arfgh »

so the showed methods in the up code depend on the viewcursor, only ? they are very explicit methods, and useful, to access the report table content.... In this case RPG, the table grid control is filtering from the subform... but you are saying that SQL way will throw speed ?
OpenOffice last version | Mageia Linux x64 | Ubuntu Linux | Windows 8.1 Enterprise x64 | Java last version
RPG
Volunteer
Posts: 2250
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: Howto get TextTable object, without getViewCursor()

Post by RPG »

The table control is for displaying the result. I think it is not good to talk about the viewcursor when you are working with a tablecontrol. A table control is part of a data-form as you see in the form-navigator. The data-form which contains the table-control is responsible for the data. It does use SQL-code for this.

I think working with macros in a real report, old-style or new-new-style is not a good idea.

Working with SQL code is most of the time faster. But people are real good in writing wrong SQL code what is slow. But those people can also not write macro code.

Romke
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
arfgh
Posts: 566
Joined: Tue Mar 05, 2013 6:44 pm

Re: Howto get TextTable object, without getViewCursor()

Post by arfgh »

But RPG, what i asked is just about to use these explicit methods to access de table data, but WITHOUT getViewCursor(). The idea is to use the subroutine from a label that acts as hyperlink. What i dont understand is why the api contain these explicit methods to access the cells from the getViewCursor, and not by other way... that is what i am looking for.

Also, what you mean with old style and new style ?

And also, the own tablegrid control should give a way to access its data, even faster than using sql.... in the case of using the viewcursor way to entering the table content in a base Report, it is very fast, i tested it.
OpenOffice last version | Mageia Linux x64 | Ubuntu Linux | Windows 8.1 Enterprise x64 | Java last version
RPG
Volunteer
Posts: 2250
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: Howto get TextTable object, without getViewCursor()

Post by RPG »

Your macro code is about searching records. That can better be done with SQL. I believe that that textboxes do have something as a text cursor but that is not a view cursor.

Your first task a to know what kind of table you use.

Romke
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
RPG
Volunteer
Posts: 2250
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: Howto get TextTable object, without getViewCursor()

Post by RPG »

I did found this Viewcursor and Selection in Formatted Textfield (View topic) • Apache OpenOffice Community Forum. But this is only for the viewcursor in a Text Box. Be aware that it is not a Text Box in a Grid-control. I think it will also not help for searching.

Romke
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
Post Reply