Hi all,
I don't know if I'm doing something wrong but I'm trying to retrieve the
text from the header / footer of a text document and I get a runtime
exception.
I've seen that if there is no tables in the header/footer I have no problem
for retrieving the text contents but if the header/footer only contains
a table (filled, of course, with some text), I get the following exception:
com.sun.star.uno.RuntimeException: no text available
public String getHeaderText(XComponent doc0) throws Exception {
StringBuffer contents = new StringBuffer("");
String header = null;
XTextDocument textComponent = (XTextDocument)
UnoRuntime.queryInterface(XTextDocument.class, doc0);
XTextCursor textCursor = textComponent.getText().createTextCursor();
XPropertySet xPageProps =
(XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, textCursor);
String jlsPageStyleName = (String)
xPageProps.getPropertyValue("PageStyleName");
XStyleFamiliesSupplier xSupplier = (XStyleFamiliesSupplier)
UnoRuntime.queryInterface( XStyleFamiliesSupplier.class, textComponent);
XNameAccess xFamilies = (XNameAccess)
UnoRuntime.queryInterface(XNameAccess.class, xSupplier.getStyleFamilies());
XNameContainer xFamily = (XNameContainer)
UnoRuntime.queryInterface(XNameContainer.class,xFamilies.getByName("PageStyles"));
XStyle xStyle = (XStyle) UnoRuntime.queryInterface(XStyle.class,
xFamily.getByName(jlsPageStyleName));
XPropertySet xStyleProps = (XPropertySet)
UnoRuntime.queryInterface(XPropertySet.class, xStyle);
xStyleProps.setPropertyValue( "HeaderIsOn", new Boolean(true));
XText xHeaderText = (XText) UnoRuntime.queryInterface(XText.class,
xStyleProps.getPropertyValue("HeaderText"));
XTextCursor xTextCursor* = xHeaderText.createTextCursor();*
header = xTextCursor.getText().getString();
contents.append(header);
contents.append("\r\n");
return contents.toString();
}
I get the exception when the highlighted line is executed.
Could someone help me with this problem?
Thank you very much!