@Transactional(readOnly = false)
public void importPsd(MultipartFile file) throws Exception {
List list = new ArrayList();
Map rsultMap = new HashMap();
AutoCode auto =new AutoCode();
Workbook workbook = null;
String fileName = file.getOriginalFilename();
if(fileName.endsWith("xls")) {
//2003
try {
workbook = new HSSFWorkbook(file.getInputStream());
} catch (Exception e) {
e.printStackTrace( );
}
}else if(fileName.endsWith("xlsx")) {
try {
//2007
workbook = new XSSFWorkbook(file.getInputStream());
} catch (Exception e) {
e.printStackTrace( );
}
}else {
try {
throw new Exception("文件不是Excel文件");
} catch (Exception e) {
e.printStackTrace();
}
}
Sheet sheet = workbook.getSheet("export");
int rows = sheet.getLastRowNum();//指定行数。一共多少+
if(rows==0) {
try {
throw new Exception("请填写行数");
} catch (Exception e) {
e.printStackTrace();
}
}
for (int i = 2; i < rows+1; i++) {
//读取左上端单元格
Row row = sheet.getRow(i);
//行不为空
if(row != null) {
//创建实体类
SyPsyhPsd syPsyhPsd = new SyPsyhPsd();
//读取第一个内容
String rq = getCellValue(row.getCell(0));
syPsyhPsd.setRq(rq);
//读取第二个内容
/*String khpk = getCellValue(row.getCell(1));
syPsyhPsd.setKhpk(khpk);;*/
//读取第三个内容
String zzsj = getCellValue(row.getCell(1));
syPsyhPsd.setZzsj(zzsj);
//读取第四个内容
String zwsj = getCellValue(row.getCell(2));
syPsyhPsd.setZwsj(zwsj);
//读取第五个内容
String hwsx = getCellValue(row.getCell(3));
syPsyhPsd.setHwsx(hwsx);