incubator-ooo-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject [Bug 120625] [UNO API]can't get the text of "TextField PageNumber" by XTextDocument.getText()
Date Tue, 21 Aug 2012 02:17:10 GMT
https://issues.apache.org/ooo/show_bug.cgi?id=120625

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

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

--- Comment #1 from Ariel Constenla-Haile <arielch@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.

Mime
View raw message