TSAttachment tsAttachment = systemService.getEntity(TSAttachment.class,ttachementId); //获得excel.
List<CcReportFormEntity> list = reportFormService.getPartsList(tsAttachment);//获取表中数据 调用serice
public List<CcReportFormEntity> getPartsList(TSAttachment tsAttachment) {
try {
String realpath = ResourceUtil.getConfigByName("realpath");
String downpath = realpath + tsAttachment.getRealpath();// 拼接全路径
List<CcReportFormEntity> list = new ArrayList<CcReportFormEntity>();
FileInputStream fis = new FileInputStream(downpath);
Workbook wb = new HSSFWorkbook(fis);
Sheet sht = wb.getSheetAt(0);
for (Row r : sht) {
if (r.getRowNum() < 1) {
continue;
}
CcReportFormEntity reportFormEntity = new CcReportFormEntity();
reportFormEntity.setModelNumber(r.getCell(0).getStringCellValue()); 取得每一排的第一列
list.add(reportFormEntity);
}
fis.close();
return list;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}