示例#1
0
    @Override
    public void processRecord(final Record record) {
      switch (record.getSid()) {
        case BOFRecord.sid:
          // 开始解析到workboot sheet 等
          BOFRecord bof = (BOFRecord) record;
          if (bof.getType() == bof.TYPE_WORKBOOK) {
            // workbook
          } else if (bof.getType() == bof.TYPE_WORKSHEET) {
            // sheet
          }
          break;
        case BoundSheetRecord.sid:
          // 开始解析BundleSheet
          BoundSheetRecord bsr = (BoundSheetRecord) record;
          // bsr.getSheetname() 得到sheet name
          break;
        case RowRecord.sid:
          // 开始解析行
          RowRecord rowrec = (RowRecord) record;
          break;
        case NumberRecord.sid:
          // 解析一个Number类型的单元格值
          NumberRecord numrec = (NumberRecord) record;
          // numrec.getRow()  numrec.getColumn()   numrec.getValue()

          // 非第一行 第一列
          if (numrec.getRow() > 0 && numrec.getColumn() == 0) {
            current = new ExcelData();
            current.setId(Double.valueOf(numrec.getValue()).longValue());
          }
          break;
        case SSTRecord.sid:
          // SSTRecords存储了在Excel中使用的所有唯一String的数组
          sstrec = (SSTRecord) record;
          break;
        case LabelSSTRecord.sid:
          // 解析一个String类型的单元格值(存储在SSTRecord)
          LabelSSTRecord lrec = (LabelSSTRecord) record;

          if (lrec.getRow() > 0 && lrec.getColumn() == 1) {
            current.setContent(sstrec.getString(lrec.getSSTIndex()).getString());
            dataList.add(current);

            totalSize++;

            // 最后一个单元格时 判断是否该写了
            if (totalSize % batchSize == 0) {
              doBatchSave(dataList);
              dataList.clear();
            }
          }
          break;
      }
    }