jAVA批量导入excel数据代码示例

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

public ReturnInfo importCardInfo(CardFormBean theForm, User user,
ArrayList temp) {
final int ROW_OF_SHEET = 50000; // 每个sheet中的最大行数
final int COL_OF_SHEET = 5; // 每个sheet中的列数
final int COL_OF_SHEET_2 = 11; // 每个sheet中的列数
ReturnInfo info = new ReturnInfo();
InputStream is = null;
jxl.Workbook rwb = null;
try {
is = theForm.getImportAll().getInputStream();
rwb = Workbook.getWorkbook(is);
int sheet = rwb.getNumberOfSheets();
for (int s = 0; s < sheet; s++) {
Sheet rs = rwb.getSheet(s);
rwb.getSheets();
int rows = rs.getRows();

int cols = rs.getColumns();
FileLog.debugLog("rows:" + rows);
FileLog.debugLog("cols:" + cols);
if (rows == 0)
continue;

if (rows > ROW_OF_SHEET) {
info.setFlag(false);
info.setInfo("第" + (s + 1) + "sheet中的行数:" + rows
+ " 超过最大行数限制:" + ROW_OF_SHEET);
return info;
}
if (cols != COL_OF_SHEET && cols != COL_OF_SHEET_2) {
info.setFlag(false);
info.setInfo("第" + (s + 1) + "sheet中的列数:" + cols
+ " 不符!目前列数是:" + COL_OF_SHEET+"或:"+ROW_OF_SHEET);
return info;
}
if(cols == COL_OF_SHEET){
for (int i = 0; i < rows; i++) {
CardBean bean = new CardBean();
bean.setCard_id(rs.getCell(0, i).getContents().trim());
bean.setCustType(rs.getCell(1, i).getContents().trim());
bean.setValid_date(rs.getCell(2, i).getContents().trim());
bean.setBank_fee(rs.getCell(3, i).getContents().trim());
bean.setSubway_fee(rs.getCell(4, i).getContents().trim());
bean.setStatus("0");
bean.setCardAppStatus("0");
temp.add(bean);
}
}else if(cols == COL_OF_SHEET_2){
for (int i = 0; i < rows; i++) {
CardBean bean = new CardBean();
bean.setCard_id(rs.getCell(0, i).getContents().trim());
bean.setCustType(rs.getCell(1, i).getContents().trim());
bean.setValid_date(rs.getCell(2, i).getContents().trim());
bean.setBank_fee(rs.getCell(3, i).getContents().trim());
bean.setSubway_fee(rs.getCell(4, i).getContents().trim());
bean.setAppNo(rs.getCell(5, i).getContents().trim());
bean.setStatus(rs.getCell(6, i).getContents().trim());
bean.setCardAppStatus(rs.getCell(7, i).getContents().trim());
bean.setCardBrand(rs.getCell(8, i).getContents().trim());
bean.setVersionId(rs.getCell(9, i).getContents().trim());
bean.setIccid(rs.getCell(10, i).getContents().trim());
temp.add(bean);
}
}

}
} catch (Exception e) {
FileLog.errorLog(e);
info.setFlag(false);
info.setInfo("导入卡信息文件失败!");
return info;
}
info.setFlag(true);
info.setInfo("导入卡信息文件成功!");
return info;
}

相关文档
最新文档