Difference between revisions of "Documentation/DevGuide/Spreadsheets/Access to Text Content"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (FINAL VERSION FOR L10N)
 
Line 49: Line 49:
 
The <code>SheetCell</code> interface <idl>com.sun.star.text.XTextFieldsSupplier</idl> contains methods that provide access to the collection of text fields in the cell. For details on inserting text fields, refer to [[Documentation/DevGuide/Text/Text Fields|Text Fields]].
 
The <code>SheetCell</code> interface <idl>com.sun.star.text.XTextFieldsSupplier</idl> contains methods that provide access to the collection of text fields in the cell. For details on inserting text fields, refer to [[Documentation/DevGuide/Text/Text Fields|Text Fields]].
  
{{Documentation/Note|Currently, the only possible text field in Calc cells is the hyperlink field <idl>com.sun.star.text.textfield.URL</idl>.}}
+
{{Note|Currently, the only possible text field in Calc cells is the hyperlink field <idl>com.sun.star.text.textfield.URL</idl>.}}
  
 
{{PDL1}}
 
{{PDL1}}
  
 
[[Category:Documentation/Developer's Guide/Spreadsheet Documents]]
 
[[Category:Documentation/Developer's Guide/Spreadsheet Documents]]

Latest revision as of 20:56, 3 July 2018



The service com.sun.star.text.Text supports the modification of simple or formatted text contents. Changing text contents and text formatting is provided by the interface com.sun.star.text.XText as discussed in First Steps. Refer to chapter Editing Text for further information. It implements the interfaces com.sun.star.container.XEnumerationAccess that provides access to the paragraphs of the text and the interface com.sun.star.text.XText to insert and modify text contents. For detailed information about text handling, see Editing Text.

 // --- Insert two text paragraphs into the cell. ---
 com.sun.star.text.XText xText = (com.sun.star.text.XText)
     UnoRuntime.queryInterface(com.sun.star.text.XText.class, xCell);
 com.sun.star.text.XTextCursor xTextCursor = xText.createTextCursor();
 
 xText.insertString(xTextCursor, "Text in first line.", false);
 xText.insertControlCharacter(xTextCursor,
     com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, false);
 xText.insertString(xTextCursor, "Some more text.", false);
 
 // --- Query the separate paragraphs. ---
 String aText;
 com.sun.star.container.XEnumerationAccess xParaEA =
     (com.sun.star.container.XEnumerationAccess) UnoRuntime.queryInterface(
         com.sun.star.container.XEnumerationAccess.class, xCell);
 com.sun.star.container.XEnumeration xParaEnum = xParaEA.createEnumeration();
 
 // Go through the paragraphs
 while (xParaEnum.hasMoreElements()) {
     Object aPortionObj = xParaEnum.nextElement();
     com.sun.star.container.XEnumerationAccess xPortionEA =
         (com.sun.star.container.XEnumerationAccess) UnoRuntime.queryInterface(
             com.sun.star.container.XEnumerationAccess.class, aPortionObj);
     com.sun.star.container.XEnumeration xPortionEnum = xPortionEA.createEnumeration();
     aText = "";
 
     // Go through all text portions of a paragraph and construct string.
     while (xPortionEnum.hasMoreElements()) {
         com.sun.star.text.XTextRange xRange =
             (com.sun.star.text.XTextRange) xPortionEnum.nextElement();
         aText += xRange.getString();
     }
     System.out.println("Paragraph text: " + aText);
 } 

The SheetCell interface com.sun.star.text.XTextFieldsSupplier contains methods that provide access to the collection of text fields in the cell. For details on inserting text fields, refer to Text Fields.

Documentation note.png Currently, the only possible text field in Calc cells is the hyperlink field com.sun.star.text.textfield.URL.
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages