Writer's tables, read a cell column span

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
blu
Posts: 3
Joined: Mon Jul 28, 2014 8:33 am

Writer's tables, read a cell column span

Post by blu »

Hello,

in a Writer table, using a BASIC macro how can I get how many columns a cell spans ? There is a property, called RowSpan, for reading the numbers of rows but I couldn't find one for the number of columns. Otherwise, is there a way to read the cell size or coordinates (in pixel, mm or inch) ?

My code is something like this:

Code: Select all

sub subTable(oTable)
	mCellnames = oTable.getCellNames
	for i = 0 to uBound(mCellNames)
		sCellName = mCellNames(i)
		oCell = oTable.getCellByName(sCellName)
		...
	next
end sub
Thanks
OpenOffice 4.1.0 Win 7 x86
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Writer's tables, read a cell column span

Post by Villeroy »

A text table supports http://www.openoffice.org/api/docs/comm ... eData.html which returns an array of arrays where each inner array represents one row of data. The values of a row array are either string or double.

Code: Select all

a() = oTable.getDataArray()
For i = 0 to uBound(a())
 aRow = a(i)
  for j = 0 to uBound(aRow())
    print i, j, aRow(j)
  next
next
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
blu
Posts: 3
Joined: Mon Jul 28, 2014 8:33 am

Re: Writer's tables, read a cell column span

Post by blu »

Thanks Villeroy but I cannot find the column span information. For example, for this table:

Code: Select all

-------------------
|    Aaa    | Bbb |
-------------------
| Ccc |    Ddd    |
-------------------
| Eee | Fff | Ggg |
-------------------
with your code I get:
0 0 Aaa
0 1 Bbb
1 0 Ccc
1 1 Ddd
2 0 Eee
2 1 Fff

But I needed 0 2 Bbb, as Bbb starts on column 2, also the last cell "2 2 Ggg" is missing.
OpenOffice 4.1.0 Win 7 x86
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Writer's tables, read a cell column span

Post by Villeroy »

I don't know. Read the tutorials and programming guides.
http://www.pitonyak.org/oo.php (e.g. OO Macros Explained, chapter 14.9)
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
blu
Posts: 3
Joined: Mon Jul 28, 2014 8:33 am

Re: Writer's tables, read a cell column span

Post by blu »

Ok, thanks.
Otherwise, do you know if there is a property for the cell size in pixel or mm ?

EDIT: thanks for the link!
OpenOffice 4.1.0 Win 7 x86
User avatar
RoryOF
Moderator
Posts: 34619
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Writer's tables, read a cell column span

Post by RoryOF »

If there is such a property (I don't know), it will be in dimensions (cm, inches etc) not in pixels.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Writer's tables, read a cell column span

Post by Villeroy »

Nobody knows all this shit by heart. We simply look it up: [Tutorial] Introduction into object inspection with MRI
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
_savage
Posts: 187
Joined: Sun Apr 21, 2013 12:55 am

Re: Writer's tables, read a cell column span

Post by _savage »

Hello blu, did you ever figure this out? Just curious… ;)
Mac 10.14 using LO 7.2.0.2, Gentoo Linux using LO 7.2.3.2 headless.
JeJe
Volunteer
Posts: 2785
Joined: Wed Mar 09, 2016 2:40 pm

Re: Writer's tables, read a cell column span

Post by JeJe »

Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
Lupp
Volunteer
Posts: 3553
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: Writer's tables, read a cell column span

Post by Lupp »

It's a fact: TextTables are either simple or a mess. A simple TexTable is one without any merging.
Writer may handle complex tables with internal means (losely based on html standards?) but the API only gives the related information for cells merged across rows (RowSpan) there is no respective property concerning the columns, and it is (seems to me) next to impossible to get that info by different means. (I tried a few weeks ago just for curiosity.)

The DataArray won't help in many cases. When asked for a range's DataArray even my "most enhanced version" LibO 6.4.2 surrenders with a message like "table too complex" as soon as skew merging occurs.

(Complex tables created by one-level-merging are correctly handled in some cases as long as no offset between merged ranges is included.)
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Writer's tables, read a cell column span

Post by Villeroy »

5 minutes of playing with text tables and MRI tells you everything you need to know.
When using a DataArray with the table provided by blu:

Code: Select all

-------------------
|    Aaa    | Bbb |
-------------------
| Ccc |    Ddd    |
-------------------
| Eee | Fff | Ggg |
-------------------
the DataArray takes as many columns as in the first row and cuts off any columns beyond. This is why "Ggg" is not included.
When the first row has more columns, getDataArray throws an error because the second row can not be filled.
The table has a collection of rows but no collection of columns.
When merging cells vertically or splitting them horizontally, the collection of rows becomes void too.

YOU have to write a program which is able to analyse the table by means of c.s.s.text.TableColumnSeparator, getCellNames() and possibly other attributes. There is no universal solution for this until YOU find one.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply