Download it now!
Bug 51925 - [BASIC] Writer Table getColumns().getByIndex(i) returns null, where it should not
Summary: [BASIC] Writer Table getColumns().getByIndex(i) returns null, where it shoul...
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
(earliest affected)
3.5.4 release
Hardware: Other All
: medium normal
Assignee: Not Assigned
Depends on:
Blocks: Macro-UNOAPI
  Show dependency treegraph
Reported: 2012-07-09 19:37 UTC by Olivier Hallot
Modified: 2019-09-19 12:37 UTC (History)
4 users (show)

See Also:
Crash report or crash signature:

Text document showing bug in getColumns.getByIndex() flaw. (10.27 KB, application/vnd.oasis.opendocument.text)
2012-07-09 19:37 UTC, Olivier Hallot

Note You need to log in before you can comment on or make changes to this bug.
Description Olivier Hallot 2012-07-09 19:37:08 UTC
Created attachment 64047 [details]
Text document showing bug in getColumns.getByIndex() flaw.

The following piece of BASIC returns a null object where it should not.

REM  *****  BASIC  *****

Sub Main
nLin = 10
nCol = 7

oText = ThisComponent.getText()

'Create tabela
	oTabela = ThisComponent.createInstance("")
	oTabela.initialize ( nLin, nCol )
	oCursorT = oText.createTextCursor()
	oText.insertTextContent(oCursorT, oTabela, True)
        oColuna = oTabela.getColumns().getByIndex(0)
        xray oColuna
	'oColuna.IsAutoWidth = False
	'oColuna.Width = 4440
End Sub

oColuna returns NULL where it should have returned an object. xray is a well known macro to inspect objects.

No way to set a column width, and other column properties.

The attached document provides a living example.

Please execute macro Main in Standard library.
Comment 1 Olivier Hallot 2012-07-15 03:14:31 UTC
getByIndex() is not working fot columns, work for rows.
Comment 2 Olivier Hallot 2012-07-20 13:51:19 UTC
A complete description of why this stupid situation is there:

In a nutshell: the getByIndex() method is there to fulfill the API completness, but it wasn't implemented, and deliberately returns NULL.
Comment 3 bfoman (inactive) 2013-01-28 12:28:17 UTC status:
Fixed in CWS tl14.
Files changed:
- unotbl.cxx  new revision:
Comment 4 tommy27 2013-10-19 18:55:54 UTC
adding BASIC expert to CC  list
Comment 5 Joel Madero 2014-07-21 01:41:54 UTC
@Olivier - I get a basic runtime error with your sample - is this what you are referring to or should I be seeing something different?
Comment 6 Noel Power 2014-07-21 08:20:12 UTC
(In reply to comment #4)
> adding BASIC expert to CC  list

it's got nothing to do with basic, it's according to comment #2 and api implementation issue
Comment 7 tommy27 2014-07-21 08:52:24 UTC
sorry Noel for disturbing you. my bad :-)
Comment 8 Owen Genat (retired) 2014-07-28 11:45:15 UTC
I think according to comment 2 and comment 6 this report can be confirmed. As comment seven in the related Apache issue indicates, /core/sw/source/core/unocore/unotbl.cxx was changed back in 2005 to return null because "the internal table representation does not have columns".

The related change appears to be 904d699f6d76154e541c35395c69d6c85712ec2a which states: 2005/07/13 13:37:25 tl #i21669# SwXTableColumns::getByIndex returns an empty XInterface now.

Exactly how the issue might be resolved remains a problem, but the report at least would seem accurate. Apache issue added to See Also list for reference. Status set to NEW.
Comment 9 QA Administrators 2015-09-04 02:48:47 UTC Comment hidden (obsolete)
Comment 10 Olivier Hallot 2015-09-04 11:26:36 UTC
The bug is still valid as of today, any version.
Comment 11 QA Administrators 2016-09-20 10:29:58 UTC Comment hidden (obsolete)
Comment 12 Buovjaga 2019-08-11 10:39:12 UTC
Original macro seems to require Xray extension to be installed. I tested with MsgBox(oColuna) instead (empty result and "Object variable not set")

Arch Linux 64-bit
Build ID: 37fc9f51a8de11d40632e8cda17ccf1fa4b1f503
CPU threads: 8; OS: Linux 5.2; UI render: default; VCL: gtk3; 
Locale: fi-FI (fi_FI.UTF-8); UI-Language: en-US
Calc: threaded
Built on 6 August 2019