[]
        
(Showing Draft Content)

ReplaceOptions

Class ReplaceOptions

java.lang.Object
com.grapecity.documents.excel.ReplaceOptions

public class ReplaceOptions extends Object
Wraps the optional parameters used by IRange.replace(Object,Object,ReplaceOptions).

Use this class to configure how content is matched and replaced in a range, including whether the search matches the whole cell content or part of it, the search order, case sensitivity, double-byte matching, and optional search and replacement formats. This wrapper keeps the replace API consistent when optional settings are provided.


 worksheet.getRange("A1:A2").setValue(new Object[][] {
     {"Draft"},
     {"Draft plan"}
 });
 ReplaceOptions options = new ReplaceOptions();
 options.setLookAt(LookAt.Whole);
 worksheet.getRange("A1:A2").replace("Draft", "Final", options);
 
  • Constructor Details

    • ReplaceOptions

      public ReplaceOptions()
  • Method Details

    • getLookAt

      public final LookAt getLookAt()
      Gets how the search text is matched during a replace operation.

      Returns one of the LookAt enum values that determines whether IRange.replace(Object,Object,ReplaceOptions) matches the whole search text or any part of it. The default value is LookAt.Part.

      
       worksheet.getRange("A1:A3").setValue(new Object[][] {
           {"NewYork"},
           {"York"},
           {"NewYork City"}
       });
       ReplaceOptions options = new ReplaceOptions();
       options.setLookAt(LookAt.Whole);
       LookAt lookAt = options.getLookAt();
       worksheet.getRange("A1:A3").replace("NewYork", "Seattle", options);
       
      Returns:
      The LookAt enum value that specifies whether the replace operation matches the whole search text or any part of it.
    • setLookAt

      public final void setLookAt(LookAt value)
      Sets how the search text is matched during a replace operation.

      Use this method to specify whether the replace operation matches the whole search text or any part of it. The default value is LookAt.Part.

      
       worksheet.getRange("A1:A3").setValue(new Object[][] {
           {"NewYork"},
           {"York"},
           {"NewYork City"}
       });
       ReplaceOptions options = new ReplaceOptions();
       options.setLookAt(LookAt.Whole);
       worksheet.getRange("A1:A3").replace("NewYork", "Seattle", options);
       
      Parameters:
      value - The LookAt value that specifies whether the replace operation matches the whole search text or any part of it. Can be null.
    • getSearchOrder

      public final SearchOrder getSearchOrder()
      Gets the search order.

      The search order determines how a range is traversed during a replace operation. For example, SearchOrder.ByRows searches across a row before moving to the next row, and SearchOrder.ByColumns searches down a column before moving to the next column.

      
       worksheet.getRange("A1:B2").setValue(new Object[][] {
           {"NewYork", "Draft"},
           {"Review", "NewYork"}
       });
       ReplaceOptions options = new ReplaceOptions();
       options.setSearchOrder(SearchOrder.ByColumns);
       SearchOrder searchOrder = options.getSearchOrder();
       worksheet.getRange("A1:B2").replace("NewYork", "Seattle", options);
       
      Returns:
      The SearchOrder enum value representing the search order.
    • setSearchOrder

      public final void setSearchOrder(SearchOrder value)
      Sets the search order used by IRange.replace(Object,Object,ReplaceOptions).

      Use this method to control how the range is traversed during a replace operation. Specify SearchOrder.ByRows to search across each row before moving to the next row, or SearchOrder.ByColumns to search down each column before moving to the next column.

      
       worksheet.getRange("A1:B2").setValue(new Object[][] {
           {"NewYork", "Draft"},
           {"Review", "NewYork"}
       });
       ReplaceOptions options = new ReplaceOptions();
       options.setSearchOrder(SearchOrder.ByColumns);
       worksheet.getRange("A1:B2").replace("NewYork", "Seattle", options);
       
      Parameters:
      value - The SearchOrder value that controls the search traversal order; null clears the current setting.
    • getMatchCase

      public final boolean getMatchCase()
      Gets whether the search is case-sensitive.

      This option controls whether IRange.replace(Object,Object,ReplaceOptions) matches letter case when searching text. The default value is false.

      
       worksheet.getRange("A1:A3").setValue(new Object[][] {
           {"newyork"},
           {"NewYork"},
           {"NEWYORK"}
       });
       ReplaceOptions options = new ReplaceOptions();
       options.setMatchCase(true);
       boolean matchCase = options.getMatchCase();
       worksheet.getRange("A1:A3").replace("newyork", "Seattle", options);
       
      Returns:
      true if the search is case-sensitive; otherwise, false. The default value is false.
    • setMatchCase

      public final void setMatchCase(boolean value)
      Sets whether the search is case-sensitive.

      This option controls whether IRange.replace(Object,Object,ReplaceOptions) matches letter case when searching text. The default value is false.

      
       worksheet.getRange("A1:A3").setValue(new Object[][] {
           {"newyork"},
           {"NewYork"},
           {"NEWYORK"}
       });
       ReplaceOptions options = new ReplaceOptions();
       options.setMatchCase(true);
       worksheet.getRange("A1:A3").replace("newyork", "Seattle", options);
       
      Parameters:
      value - true if the search is case-sensitive; otherwise, false. The default value is false.
    • getMatchByte

      public final boolean getMatchByte()
      Gets whether replacement matches double-byte characters only.

      If this property is true, double-byte characters match only double-byte characters. If this property is false, double-byte characters can match their single-byte equivalents.

      Use setMatchByte(boolean) to change this setting for IRange.replace(Object,Object,ReplaceOptions) operations.

      
       worksheet.getRange("A1:A2").setValue(new Object[][] {
           {"A"},
           {"A"}
       });
       ReplaceOptions options = new ReplaceOptions();
       options.setMatchByte(true);
       boolean matchByte = options.getMatchByte();
       worksheet.getRange("A1:A2").replace("A", "B", options);
       
      Returns:
      true if double-byte characters match only double-byte characters; false if they can match their single-byte equivalents.
    • setMatchByte

      public final void setMatchByte(boolean value)
      Sets whether replacement matches double-byte characters only.

      If this property is true, double-byte characters match only double-byte characters. If this property is false, double-byte characters can match their single-byte equivalents.

      
       worksheet.getRange("A1:A2").setValue(new Object[][] {
           {"A"},
           {"A"}
       });
       ReplaceOptions options = new ReplaceOptions();
       options.setMatchByte(true);
       worksheet.getRange("A1:A2").replace("A", "B", options);
       
      Parameters:
      value - true if double-byte characters match only double-byte characters; false if they can match their single-byte equivalents.
    • getSearchFormat

      public final IDisplayFormat getSearchFormat()
      Gets the display format used as the search criterion during a replace operation.

      Returns the IDisplayFormat used by IRange.replace(Object,Object,ReplaceOptions) to limit matching to cells whose displayed formatting matches the specified format. The default value is null.

      
       worksheet.getRange("A1").setValue("Draft");
       worksheet.getRange("A1").setNumberFormat("$0.00");
       ReplaceOptions options = new ReplaceOptions();
       options.setSearchFormat(worksheet.getRange("A1").getDisplayFormat());
       IDisplayFormat searchFormat = options.getSearchFormat();
       
      Returns:
      The search format, or null if no format criterion has been set.
    • setSearchFormat

      public final void setSearchFormat(IDisplayFormat value)
      Sets the search format for the replace operation.

      Use this method to limit IRange.replace(Object,Object,ReplaceOptions) to cells whose displayed format matches the specified IDisplayFormat.

      
       worksheet.getRange("A1").setValue("NewYork");
       worksheet.getRange("B1").setValue("NewYork");
       worksheet.getRange("A1").getFont().setBold(true);
       ReplaceOptions options = new ReplaceOptions();
       options.setSearchFormat(worksheet.getRange("A1").getDisplayFormat());
       worksheet.getRange("A1:B1").replace("NewYork", "Seattle", options);
       
      Parameters:
      value - The display format to use as the search criteria. Specify null to clear the search format.
    • getReplaceFormat

      public final IDisplayFormat getReplaceFormat()
      Gets the display format applied to replaced cells during a replace operation.

      Returns the IDisplayFormat configured for IRange.replace(Object,Object,ReplaceOptions). When this property is not null, the replace operation uses the specified display format for matched cells after their values are replaced. The default value is null.

      
       worksheet.getRange("A1").setValue("Draft");
       worksheet.getRange("C1").getFont().setColor(Color.GetBlue());
       ReplaceOptions options = new ReplaceOptions();
       options.setReplaceFormat(worksheet.getRange("C1").getDisplayFormat());
       IDisplayFormat replaceFormat = options.getReplaceFormat();
       
      Returns:
      The display format used for replacement, or null if no replacement format has been set.
    • setReplaceFormat

      public final void setReplaceFormat(IDisplayFormat value)
      Sets the display format applied to replaced cells during a replace operation.

      This method configures the IDisplayFormat used by IRange.replace(Object,Object,ReplaceOptions). When this property is not null, the replace operation applies the specified display format to matched cells after their values are replaced. Specify null to remove the replacement format setting.

      
       worksheet.getRange("A1").setValue("Draft");
       worksheet.getRange("C1").getFont().setColor(Color.GetBlue());
       ReplaceOptions options = new ReplaceOptions();
       options.setReplaceFormat(worksheet.getRange("C1").getDisplayFormat());
       worksheet.getRange("A1").replace("Draft", "Final", options);
       
      Parameters:
      value - The display format to apply to replaced cells. Specify null to clear the replacement format setting.