com.groupdocs.redaction.redactions

Class CellColumnRedaction



  • public class CellColumnRedaction
    extends TextRedaction

    Represents a text redaction that replaces text in a spreadsheet documents (CSV, Excel, etc.).


    Learn more

    The following example demonstrates removing user emails from a second column on "Customers" worksheet of a spreadsheet document.

    try (Redactor redactor = new Redactor("D:\\Sales in September.xslx"))
     {
        CellFilter filter = new CellFilter();
        filter.setColumnIndex(1); // zero-based 2nd column
        filter.setWorkSheetName("Customers");
        
        Pattern expression = Pattern.compile("^\\w+([-+.']\\w+)*@\\w+([-.]\\w+)\*\.\\w+([-.]\\w+)*$");
        RedactorChangeLog changeLog = redactor.apply(new CellColumnRedaction(filter, expression, new ReplacementOptions("[customer email]")));
        if (result.Status != RedactionStatus.Failed)
        {
           SaveOptions opt = new SaveOptions();
           opt.setAddSuffix(true);
           doc.save(opt);
        };
     }
      
    • Constructor Detail

      • CellColumnRedaction

        public CellColumnRedaction(CellFilter filter,
                           Pattern regEx,
                           ReplacementOptions options)

        Initializes a new instance of CellColumnRedaction class.

        Parameters:
        filter - Column and worksheet filter
        regEx - Regular expression to search and replace
        options - Replacement options
    • Method Detail

      • getPattern

        public final Pattern getPattern()

        Gets the regular expression to match.

        Returns:
        The regular expression to match.
      • getFilter

        public final CellFilter getFilter()

        Gets the column and worksheet filter.

        Returns:
        The column and worksheet filter.
      • getDescription

        public String getDescription()

        Returns a string, describing the redaction and its parameters.

        Overrides:
        getDescription in class Redaction
        Returns:
        Text, containing redaction name and parameters.
      • applyTo

        public RedactorLogEntry applyTo(DocumentFormatInstance formatInstance)

        Applies the redaction to a given format instance.

        Specified by:
        applyTo in class Redaction
        Parameters:
        formatInstance - An instance of a document to apply redaction
        Returns:
        Status of the redaction: success/failure and error message if any