von Jocko » Mi, 15.08.2007 12:05
So, nach einigem Dokuwälzen und experimentieren habe ich eine gangbare Lösung gefunden (bisher werden Kopf- und Fusszeilen noch nicht beachtet, das sollte aber machbar sein). Wenn man über die Paragraphen und dann deren TextPortions iteriert bekommt man alles in der von mir gewünschten Reihenfolge. Fügt man rekursive Aufrufe dazu, klappt es auch mit geschachtelten Tabellen.
Viele Grüße,
Joachim
Code: Alles auswählen
private void mkFieldModelRec(XText pxText, XListBox pxListBox) throws com.sun.star.uno.Exception {
XEnumerationAccess lxParAccess = (XEnumerationAccess) UnoRuntime.queryInterface(XEnumerationAccess.class, pxText);
XEnumeration lxParEnum = lxParAccess.createEnumeration();
while (lxParEnum.hasMoreElements()) {
Any lxAnyPar = (Any) lxParEnum.nextElement();
XServiceInfo lxInfo = (XServiceInfo) UnoRuntime.queryInterface(XServiceInfo.class, lxAnyPar);
if (lxInfo.supportsService("com.sun.star.text.Paragraph")) {
XTextContent lxPar = (XTextContent) lxAnyPar.getObject();
XEnumerationAccess lxPortionAccess = (XEnumerationAccess) UnoRuntime.queryInterface(XEnumerationAccess.class, lxPar);
XEnumeration lxPortionEnum = lxPortionAccess.createEnumeration();
while (lxPortionEnum.hasMoreElements()) {
Any lxAnyPort = (Any) lxPortionEnum.nextElement();
XPropertySet lxPortProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, lxAnyPort);
String lType = (String) lxPortProps.getPropertyValue("TextPortionType");
if (lType.equals("TextField")) {
XTextContent lxContent = (XTextContent) UnoRuntime.queryInterface(XTextContent.class, lxAnyPort);
XTextRange lxRange = lxContent.getAnchor();
XTextCursor lxCursor = pxText.createTextCursorByRange(lxRange);
XPropertySet lxCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, lxCursor);
Object lxAnyField = lxCursorProps.getPropertyValue("TextField");
XTextField lxField = (XTextField) UnoRuntime.queryInterface(XTextField.class, lxAnyField);
pxListBox.addItem(lxField.getPresentation(false), pxListBox.getItemCount());
}
}
} else if (lxInfo.supportsService("com.sun.star.text.TextTable")) {
XTextTable lxTable = (XTextTable) UnoRuntime.queryInterface(XTextTable.class, lxAnyPar);
String lCellNames[] = lxTable.getCellNames();
for (int i = 0; i < lCellNames.length; ++i) {
XCell lxCell = lxTable.getCellByName(lCellNames[i]);
XText lxCellText = (XText) UnoRuntime.queryInterface(XText.class, lxCell);
mkFieldModelRec(lxCellText, pxListBox);
}
}
}
}
So, nach einigem Dokuwälzen und experimentieren habe ich eine gangbare Lösung gefunden (bisher werden Kopf- und Fusszeilen noch nicht beachtet, das sollte aber machbar sein). Wenn man über die Paragraphen und dann deren TextPortions iteriert bekommt man alles in der von mir gewünschten Reihenfolge. Fügt man rekursive Aufrufe dazu, klappt es auch mit geschachtelten Tabellen.
Viele Grüße,
Joachim
[code]
private void mkFieldModelRec(XText pxText, XListBox pxListBox) throws com.sun.star.uno.Exception {
XEnumerationAccess lxParAccess = (XEnumerationAccess) UnoRuntime.queryInterface(XEnumerationAccess.class, pxText);
XEnumeration lxParEnum = lxParAccess.createEnumeration();
while (lxParEnum.hasMoreElements()) {
Any lxAnyPar = (Any) lxParEnum.nextElement();
XServiceInfo lxInfo = (XServiceInfo) UnoRuntime.queryInterface(XServiceInfo.class, lxAnyPar);
if (lxInfo.supportsService("com.sun.star.text.Paragraph")) {
XTextContent lxPar = (XTextContent) lxAnyPar.getObject();
XEnumerationAccess lxPortionAccess = (XEnumerationAccess) UnoRuntime.queryInterface(XEnumerationAccess.class, lxPar);
XEnumeration lxPortionEnum = lxPortionAccess.createEnumeration();
while (lxPortionEnum.hasMoreElements()) {
Any lxAnyPort = (Any) lxPortionEnum.nextElement();
XPropertySet lxPortProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, lxAnyPort);
String lType = (String) lxPortProps.getPropertyValue("TextPortionType");
if (lType.equals("TextField")) {
XTextContent lxContent = (XTextContent) UnoRuntime.queryInterface(XTextContent.class, lxAnyPort);
XTextRange lxRange = lxContent.getAnchor();
XTextCursor lxCursor = pxText.createTextCursorByRange(lxRange);
XPropertySet lxCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, lxCursor);
Object lxAnyField = lxCursorProps.getPropertyValue("TextField");
XTextField lxField = (XTextField) UnoRuntime.queryInterface(XTextField.class, lxAnyField);
pxListBox.addItem(lxField.getPresentation(false), pxListBox.getItemCount());
}
}
} else if (lxInfo.supportsService("com.sun.star.text.TextTable")) {
XTextTable lxTable = (XTextTable) UnoRuntime.queryInterface(XTextTable.class, lxAnyPar);
String lCellNames[] = lxTable.getCellNames();
for (int i = 0; i < lCellNames.length; ++i) {
XCell lxCell = lxTable.getCellByName(lCellNames[i]);
XText lxCellText = (XText) UnoRuntime.queryInterface(XText.class, lxCell);
mkFieldModelRec(lxCellText, pxListBox);
}
}
}
}
[/code]