[]
        
首页
开发者学堂
文档
论坛
市场
生态机会
活动
立即试用
(Showing Draft Content)

CsvParseResult

Class CsvParseResult

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

public class CsvParseResult extends Object
表示解析后的 CSV 值及其数字格式。

自定义 ICsvParser 可以检查或修改此结果,以保留前导零、将文本转换为另一个受支持的值,或为导入的单元格指定数字格式。使用 setValue(Object) 或 setNumberFormat(String) 可以更新结果内容。


 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)
      初始化新的 CSV 解析结果。
      Parameters:
      value - 解析后的值。
      numberFormat - 解析后的数字格式。
  • Method Details

    • getValue

      public Object getValue()
      获取解析后的值。
      
       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:
      解析后的值。
    • setValue

      public void setValue(Object value)
      设置解析后的值。该值应为 Double、String、Boolean 或 CalcError。其他数据类型将被丢弃。
      
       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 - 解析后的值。
    • getNumberFormat

      public String getNumberFormat()
      获取解析后的数字格式。
      
       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:
      解析后的数字格式。
    • setNumberFormat

      public void setNumberFormat(String numberFormat)
      设置解析后的数字格式。
      
       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 - 解析后的数字格式。