You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openoffice.apache.org by bu...@apache.org on 2012/08/21 04:17:10 UTC

[Bug 120625] [UNO API]can't get the text of "TextField PageNumber" by XTextDocument.getText()

https://issues.apache.org/ooo/show_bug.cgi?id=120625

Ariel Constenla-Haile <ar...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |arielch@apache.org

--- Comment #1 from Ariel Constenla-Haile <ar...@apache.org> ---
(In reply to comment #0)
> Build:
> AOO350m1(Build:9610)
> 
> Steps:
>  Using UNO API  do below operation.
> 1.Launch a odt document,
> 2.Create a page number field and insert into this docment
> 3.Get the document text
> 
> But in the step3, page number is not contained in the get text.  But if I
> launch a doc document, I can get the page number in step 3.  Below is  code
> pieces.
> 
> XMultiServiceFactory sevriceFactory = (XMultiServiceFactory)
> UnoRuntime.queryInterface(XMultiServiceFactory.class, document);
>         XTextField  pageNumberFiled =
> (XTextField)UnoRuntime.queryInterface(XTextField.class,
> sevriceFactory.createInstance("com.sun.star.text.textfield.PageNumber"));
>        
>         XPropertySet props =
> (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, pageNumberFiled);
>         props.setPropertyValue("NumberingType", 4);//Set page number display
> as Arabic
>        
>         XTextCursor xTextCursor = document.getText().createTextCursor();   
>         xTextCursor.gotoEnd(false);   
>    
>         document.getText().insertTextContent(document.getText().getEnd(),
> pageNumberFiled, true);
>        
> 
>         String documentString = document.getText().getString();
>         System.out.println(documentString);.


You might be missing to set the property SubType to
com.sun.star.text.PageNumberType.CURRENT

http://www.openoffice.org/api/docs/common/ref/com/sun/star/text/textfield/PageNumber.html#SubType
http://www.openoffice.org/api/docs/common/ref/com/sun/star/text/PageNumberType.html#CURRENT

If you only have one page, and it default to
com.sun.star.text.PageNumberType.PREV, the field will always be empty.
Sample AOO Basic code:

Sub Main
    Dim oDoc as Object
    oDoc = ThisComponent

    Dim oField as Object
    oField = oDoc.createInstance("com.sun.star.text.textfield.PageNumber")
    oField.setPropertyValue("SubType",
com.sun.star.text.PageNumberType.CURRENT)
    oField.setPropertyValue("NumberingType",
com.sun.star.style.NumberingType.ARABIC)

    Dim oText as Object
    oText = oDoc.getText()

    oText.insertTextContent(oText.getEnd(), oField, True)

    oDoc.getTextFields().refresh()

    Dim sText as String
    sText = oText.getString()
End Sub

-- 
You are receiving this mail because:
You are the assignee for the bug.