[]
        
(Showing Draft Content)

CsvParseResult

Class CsvParseResult

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

public class CsvParseResult extends Object
Represents the parsed CSV value and its number format.

A custom ICsvParser can inspect or modify this result to preserve leading zeros, convert text to another supported value, or assign a number format for the imported cell. Use setValue(Object) or setNumberFormat(String) to update the result contents.


 CsvOpenOptions options = new CsvOpenOptions();
 options.setParser(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%");
         }
     }
 });
 workbook.open("path/to/percentage.csv", options);
 
  • Constructor Details

    • CsvParseResult

      public CsvParseResult(Object value, String numberFormat)
      Initializes a new CSV parse result.
      Parameters:
      value - The parsed value.
      numberFormat - The parsed number format.
  • Method Details

    • getValue

      public Object getValue()
      Gets the parsed value.
      
       CsvOpenOptions options = new CsvOpenOptions();
       options.setParser(new ICsvParser() {
           public void Parse(CsvParseResult result, CsvParseContext context) {
               result.setValue(context.getText());
               Object value = result.getValue();
           }
       });
       workbook.open("path/to/data.csv", options);
       
      Returns:
      The parsed value.
    • setValue

      public void setValue(Object value)
      Sets the parsed value. The value should be Double, String, Boolean, or CalcError. Other data types are discarded.
      
       CsvOpenOptions options = new CsvOpenOptions();
       options.setParser(new ICsvParser() {
           public void Parse(CsvParseResult result, CsvParseContext context) {
               if (context.getText().startsWith("00")) {
                   result.setValue(context.getText());
               }
           }
       });
       workbook.open("path/to/data.csv", options);
       
      Parameters:
      value - The parsed value.
    • getNumberFormat

      public String getNumberFormat()
      Gets the parsed number format.
      
       CsvOpenOptions options = new CsvOpenOptions();
       options.setParser(new ICsvParser() {
           public void Parse(CsvParseResult result, CsvParseContext context) {
               if (context.getText().endsWith("%")) {
                   result.setNumberFormat("0%");
                   String numberFormat = result.getNumberFormat();
               }
           }
       });
       workbook.open("path/to/percentage.csv", options);
       
      Returns:
      The parsed number format.
    • setNumberFormat

      public void setNumberFormat(String numberFormat)
      Sets the parsed number format.
      
       CsvOpenOptions options = new CsvOpenOptions();
       options.setParser(new ICsvParser() {
           public void Parse(CsvParseResult result, CsvParseContext context) {
               if (context.getText().endsWith("%")) {
                   result.setNumberFormat("0%");
               }
           }
       });
       workbook.open("path/to/percentage.csv", options);
       
      Parameters:
      numberFormat - The parsed number format.