[]
        
(Showing Draft Content)

ICsvParser

Interface ICsvParser


public interface ICsvParser
Represents a custom CSV parser.

Assign an implementation to CsvOpenOptions.setParser(ICsvParser) to inspect each parsed CSV cell and optionally modify the parsed value or number format.


 CsvOpenOptions options = new CsvOpenOptions();
 ICsvParser parser = new ICsvParser() {
     public void Parse(CsvParseResult result, CsvParseContext context) {
         if (context.getText().startsWith("00")) {
             result.setValue(context.getText());
         }
     }
 };
 options.setParser(parser);
 workbook.open("path/to/source.csv", options);
 
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Parse(CsvParseResult csvParseResult, CsvParseContext context)
    Parses cell text and lets you inspect or modify the result produced by the built-in parser.
  • Method Details

    • Parse

      void Parse(CsvParseResult csvParseResult, CsvParseContext context)
      Parses cell text and lets you inspect or modify the result produced by the built-in parser.

      Use CsvParseContext.getText() to inspect the original CSV text, and use CsvParseResult.setValue(Object) or CsvParseResult.setNumberFormat(String) to customize the imported value.

      
       ICsvParser parser = new ICsvParser() {
           public void Parse(CsvParseResult result, CsvParseContext context) {
               if (context.getText().endsWith("%")) {
                   String text = context.getText().replace("%", "");
                   result.setValue(Double.parseDouble(text) / 100);
                   result.setNumberFormat("0%");
               }
           }
       };
       CsvOpenOptions options = new CsvOpenOptions();
       options.setParser(parser);
       workbook.open("path/to/percentage.csv", options);
       
      Parameters:
      csvParseResult - The parsed result produced by the built-in parser.
      context - The parse context of the current cell.