[]
        
(Showing Draft Content)

ITextRun

Interface ITextRun


public interface ITextRun
Represents a range of characters in a IRichText object.

An ITextRun object stores the text and character-level formatting for a contiguous portion of rich text in a cell. You can obtain this interface from IRichText.add(String) or from a character range returned by IRange.characters(int,int).


 IRichText richText = worksheet.getRange("A1").getRichText();
 ITextRun textRun = richText.add("Document");
 textRun.getFont().setBold(true);
 textRun.setText("Document Solutions");
 
  • Method Details

    • getFont

      IFont getFont()
      Gets the font settings of current text run.

      Use the returned IFont object to access or modify the font formatting applied to the current text run.

      
       IRichText richText = worksheet.getRange("A1").getRichText();
       ITextRun run = richText.add("Document");
       IFont font = run.getFont();
       font.setBold(true);
       
      Returns:
      The font settings of the current text run.
    • getText

      String getText()
      Gets the text of the current text run.

      Use this method to retrieve the character sequence represented by this run in its parent IRichText object.

      
       IRichText richText = worksheet.getRange("A1").getRichText();
       ITextRun run = richText.add("Document Solutions");
       String text = run.getText();
       
      Returns:
      The text of the current text run.
    • setText

      void setText(String text)
      Sets the text of the current text run.

      Use this method to replace the character sequence represented by this run in its parent IRichText object.

      
       IRichText richText = worksheet.getRange("A1").getRichText();
       ITextRun run = richText.add("Document Solutions");
       run.setText("Sample");
       
      Parameters:
      text - The text of the current text run.
    • delete

      void delete()
      Deletes this ITextRun from its parent IRichText object.

      Use this method to remove the current text run from the rich text content of a cell.

      
       IRichText richText = worksheet.getRange("A1").getRichText();
       richText.add("Hello");
       ITextRun textRun = worksheet.getRange("A1").characters(1, 3);
       textRun.delete();
       
    • insertBefore

      ITextRun insertBefore(String text)
      Inserts a new ITextRun before the current text run.

      Use this method to add a new text run immediately before the current run within the parent IRichText object.

      
       IRichText richText = worksheet.getRange("A1").getRichText();
       richText.add("Hello");
       ITextRun textRun = worksheet.getRange("A1").characters(1, 3);
       ITextRun insertedRun = textRun.insertBefore("World");
       insertedRun.getFont().setBold(true);
       
      Parameters:
      text - The text of the newly inserted text run.
      Returns:
      The newly created ITextRun.
    • insertAfter

      ITextRun insertAfter(String text)
      Inserts a new ITextRun after the current text run.

      Use this method to add a new text run immediately after the current run within the parent IRichText object.

      
       IRichText richText = worksheet.getRange("A1").getRichText();
       richText.add("Hello");
       ITextRun textRun = worksheet.getRange("A1").characters(1, 3);
       ITextRun insertedRun = textRun.insertAfter("World");
       insertedRun.getFont().setBold(true);
       
      Parameters:
      text - The text of the newly inserted text run.
      Returns:
      The newly created ITextRun, or null if the current text run is no longer available in the parent rich text object.