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

CsvParseContext

Class CsvParseContext

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

public class CsvParseContext extends Object
表示用于解析当前 CSV 单元格的上下文。

该上下文提供正在解析的 CSV 单元格从零开始的行索引和列索引,以及自定义解析器更改解析结果之前的原始单元格文本。


 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)
      初始化新的 CSV 解析上下文。
      Parameters:
      row - 当前单元格从零开始的行索引。
      column - 当前单元格从零开始的列索引。
      text - 当前单元格的原始文本。
  • Method Details

    • getRow

      public int getRow()
      获取当前单元格的行索引。
      
       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:
      当前单元格从零开始的行索引。
    • getColumn

      public int getColumn()
      获取当前单元格的列索引。
      
       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:
      当前单元格从零开始的列索引。
    • getText

      public String getText()
      获取当前单元格解析前的原始文本。
      
       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:
      当前单元格的原始文本。