<dependency> <groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.1.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.ws.rs/javax.ws.rs-api -->
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.1.1</version>
</dependency>
@Test public void testExcel() throws IOException { //解析Excel
List temp = new ArrayList();
FileInputStream fileIn = new FileInputStream("d:/test/111.xls");
//根據指定的文件輸入流導入Excel從而產生Workbook對象
Workbook wb0 = new HSSFWorkbook(fileIn);
//獲取Excel文檔中的第一個表單
Sheet sht0 = wb0.getSheetAt(0);
//對Sheet中的每一行進行迭代
for (Row r : sht0) {
System.out.println("第"+r.getRowNum()+"行-----------");
//如果當前行的行號(從0開始)未達到2(第三行)則從新循環
if (r.getRowNum() < 1) {
continue;
}
Servicecatalog servicecatalog = new Servicecatalog();
double id= r.getCell(0).getNumericCellValue();
servicecatalog.setId((long) id);
double type = r.getCell(1).getNumericCellValue();
servicecatalog.setType((int) type);
String name = r.getCell(2).getStringCellValue();
servicecatalog.setName(name);
// String code = r.getCell(3).getStringCellValue();
// double parentId = r.getCell(4).getNumericCellValue();
// String creater = r.getCell(5).getStringCellValue();
// Date create_time = r.getCell(6).getDateCellValue();
// Date update_time = r.getCell(7).getDateCellValue();
double yn= r.getCell(8).getNumericCellValue();
servicecatalog.setYn((int) yn);
// double showorder= r.getCell(9).getNumericCellValue();
// String bak1= r.getCell(10).getStringCellValue();
try {
String status= r.getCell(11).getStringCellValue();
}catch (Exception ex){
double statua1= r.getCell(11).getNumericCellValue();
servicecatalog.setStatus((int) statua1);
}
System.out.println(JSON.toJSONString(servicecatalog));
servicecatalogService.saveRapServicecatalog(servicecatalog);
// String remark= r.getCell(12).getStringCellValue();
// // System.out.println("id="+id+" type="+type+" name="+name+" code="+code+"parentId="+parentId+" creater="+creater+" create_tim="+create_time+ // " update_time="+update_time+"yn="+" bak1="+bak1+" showorder="+showorder+" status="+status+" remark="+remark); }