[]
        
(Showing Draft Content)

CsvParseContext

Class CsvParseContext

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

public class CsvParseContext extends Object
Represents the context for parsing the current CSV cell.

The context provides the zero-based row and column indexes of the CSV cell being parsed, together with the original cell text before the custom parser changes the parsed result.


 CsvOpenOptions options = new CsvOpenOptions();
 options.setParser(new ICsvParser() {
     public void Parse(CsvParseResult result, CsvParseContext context) {
         if (context.getColumn() == 0 && context.getText().startsWith("00")) {
             result.setValue(context.getText());
         }
     }
 });
 workbook.open("path/to/data.csv", options);
 
  • Constructor Details

    • CsvParseContext

      public CsvParseContext(int row, int column, String text)
      Initializes a new CSV parse context.
      Parameters:
      row - The zero-based row index of the current cell.
      column - The zero-based column index of the current cell.
      text - The original text of the current cell.
  • Method Details

    • getRow

      public int getRow()
      Gets the row index of the current cell.
      
       CsvOpenOptions options = new CsvOpenOptions();
       options.setParser(new ICsvParser() {
           public void Parse(CsvParseResult result, CsvParseContext context) {
               int row = context.getRow();
               if (row > 0) {
                   result.setValue(context.getText());
               }
           }
       });
       workbook.open("path/to/data.csv", options);
       
      Returns:
      The zero-based row index of the current cell.
    • getColumn

      public int getColumn()
      Gets the column index of the current cell.
      
       CsvOpenOptions options = new CsvOpenOptions();
       options.setParser(new ICsvParser() {
           public void Parse(CsvParseResult result, CsvParseContext context) {
               int column = context.getColumn();
               if (column == 0 && context.getText().startsWith("00")) {
                   result.setValue(context.getText());
               }
           }
       });
       workbook.open("path/to/data.csv", options);
       
      Returns:
      The zero-based column index of the current cell.
    • getText

      public String getText()
      Gets the original text of the current cell before parsing.
      
       CsvOpenOptions options = new CsvOpenOptions();
       options.setParser(new ICsvParser() {
           public void Parse(CsvParseResult result, CsvParseContext context) {
               String text = context.getText();
               if (text.startsWith("00")) {
                   result.setValue(text);
               }
           }
       });
       workbook.open("path/to/data.csv", options);
       
      Returns:
      The original text of the current cell.