Problems finding a TextTable element in a .docx document

I would like to replace placeholders in an array inside a .docx text file.
With previous versions of OpenOffice it worked fine. But with the latest versions it doesn’t work anymore. The versions I tried on are 7.5.1.2 and 7.5.4.1

The previous version it worked with was 6.0

I’m not allowed to put images so you have to think of an array whose first column title is name

This is what I get now [all data is reported on one line]
name
name1, name2, name3

This is what I would like to achieve [each data is reported on a new line]
name
name1
name2
name3

I work in C# under windows and using the debugger I found the point where the behavior of OpenOffice changes

This is the method where the problem arises

private XTextTable GetBookmarkTable(string bookmarkName)
{
	XBookmarksSupplier xBookmarksSupplier = mDoc as XBookmarksSupplier;
	XNameAccess xNamedBookmarks = xBookmarksSupplier.getBookmarks();
	Any bMark = xNamedBookmarks.getByName(bookmarkName);
	XTextContent xBookmarkContent = ((Any)bMark).Value as XTextContent;
	XTextRange xBookmarkRange = xBookmarkContent.getAnchor();

	XEnumerationAccess iacc = xBookmarkRange as XEnumerationAccess;
	XEnumeration xe = iacc.createEnumeration();
	while (xe.hasMoreElements())
	{
		Any t = xe.nextElement();
		if (t.Value is XTextTable)
		{
			XTextTable readerTable = t.Value as XTextTable;
			return readerTable;
		}
	}
			return null;
}

In the old version the t.Value is XTextTable test returned true while with the new versions it returns false

How can I fix the problem?
Thanks a lot to everyone

Domenico Giuseppe Sala

Please edit your question (= modify it, don’t use a comment) to improve it.
How do you “replace placeholders in an array inside a .docx text file”? Manually with Edit>Find & Replace? with a macro? some other procedure?
What is an array here? Do you mean a table, i.e. a collection of “cells” arranged in rows and columns, each cell containing an independent sub-document made of paragraphs and/or other objects?
In what way is your finding about GetBookmarkTable is relevant to your problem? How is it related to your previous working procedure?

IIUC, “OpenOffice” (both OpenOffice.org and Apache OpenOffice) never released a “7.x” version. So - which specific software, and which specific old versions are discussed here? Without that, the “In the old version the t.Value is XTextTable test returned true while with the new versions it returns false” can’t be checked, and the reason for the change (if it happened) can’t be determined.

EDIT: (I see now “The previous version it worked with was 6.0”, so obviously the “OpenOffice” was “LibreOffice”.)

And actually, a sample VS project, and a sample document where the problem is shown, would be nice.

Welcome! I could be wrong, but it seems to me that t.Value is always XTextContent. Perhaps you should get from t.Value XPropertySet and take from it (XTextTable) xPropSet.getPropertyValue("TextTable").Value;
This is just an idea, I can’t guarantee it will work - I don’t know Writer very well and don’t know C# at all

XServiceInfo xServiceInfo = (XServiceInfo) t.Value;
if (xServiceInfo.supportsService(“com.sun.star.text.TextTable”))…
?

Hi
Very nice JohnSUN
Your idea of ​​going through the XServiceInfo interface was perfect. The problem has been solved

Thank you very much for the suggestion and also for the speed of the reply.
I also thank the other people who responded to my request for help

1 Like