excle表格模板
poi导入代码
@RestController
@RequestMapping("/per")
public class PurchaseOrderInController {
@Resource
private PurchaseOrderInService purchaseOrderInService;
@RequestMapping("/importExcel")
public void keep()throws Exception{
ImportParams params = new ImportParams();
PurchaseOrderIn orderIn = new PurchaseOrderIn();
PurchaseOrderDetailIn detailIn = new PurchaseOrderDetailIn();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
File file = new File("C:\\Users\\Administrator\\Desktop\\申购单导入.xlsx");
FileInputStream fis = new FileInputStream(file);
XSSFWorkbook xssfSheets = new XSSFWorkbook(fis);
XSSFSheet sheetAt = xssfSheets.getSheetAt(0);
int lastRowNum = sheetAt.getLastRowNum();
for(int i = 2 ;i<=lastRowNum; i ++){
XSSFRow row = sheetAt.getRow(i);
int lastCellNum = row.getLastCellNum();
for (int j = 0;j< lastCellNum;j++){
XSSFCell cell = row.getCell(0);
XSSFCell cell1 = row.getCell(1);
XSSFCell cell2 = row.getCell(2);
XSSFCell cell3 = row.getCell(3);
XSSFCell cell4 = row.getCell(4);
XSSFCell cell5 = row.getCell(5);
XSSFCell cell6 = row.getCell(6);
XSSFCell cell7 = row.getCell(7);
XSSFCell cell8 = row.getCell(8);
XSSFCell cell9 = row.getCell(9);
XSSFCell cell10 = row.getCell(10);
XSSFCell cell11 = row.getCell(11);
//申请人 申请日期
XSSFCell cell12 = row.getCell(12);
XSSFCell cell13 = row.getCell(13);
//是否需要采购
XSSFCell cell14 = row.getCell(14);
String a =cell.toString();
Double d = Double.parseDouble(a);
int i1 = d.intValue();
orderIn.setId(Integer.valueOf(i1));
orderIn.setPurchase_order_no(cell1.toString());
orderIn.setMateriel_xtk_no(cell2.toString());
String a10 = dateFormat.format(cell3.getDateCellValue());
Date parse = dateFormat.parse(a10);
orderIn.setRequire_last_date(parse);
String a4 =cell4.toString();
Double d4 = Double.parseDouble(a4);
int i4 = d4.intValue();
orderIn.setPurchase_num(Integer.valueOf(i4));
orderIn.setCustomer_name(cell5.toString());
orderIn.setCustomer_code(cell6.toString());
orderIn.setDescribe(cell7.toString());
orderIn.setBrand_name(cell8.toString());
orderIn.setBrand_code(cell9.toString());
orderIn.setProduct_type_name(cell10.toString());
orderIn.setUnits(cell11.toString());
detailIn.setP_purchase_order_id(Integer.valueOf(i1));
detailIn.setPurchaser(cell12.toString());
String a11 = dateFormat.format(cell13.getDateCellValue());
Date parse2 = dateFormat.parse(a11);
String format = dateFormat.format(parse2);
detailIn.setPurchase_date(format);
String a14 =cell14.toString();
Double d14 = Double.parseDouble(a14);
int i14 = d14.intValue();
orderIn.setIs_need_enquiry(Integer.valueOf(i14));
detailIn.setSyteline_create_date(parse);
detailIn.setSyteline_submit_date(parse);
}
}
orderIn.setOrder_type(1);
orderIn.setIs_agreement(0);
orderIn.setSource_code(1);
orderIn.setPurchase_approval_times(0);
orderIn.setSale_approval_times(0);
orderIn.setDivide_approval_times(0);
orderIn.setState(1);
orderIn.setIs_delete(0);
SimpleDateFormat f1 = new SimpleDateFormat("yyyy-MM-dd");
Date date = new Date();
orderIn.setCreate_date(date);
orderIn.setCreator("system");
detailIn.setCreator("system");
detailIn.setCreate_date(date);
detailIn.setIs_delete(0);
detailIn.setState(0);
purchaseOrderInService.addPurchaseOrderIn(orderIn);
purchaseOrderInService.addPurchaseOrderDetailIn(detailIn);
}
}
仅供参考~ 点下关注 亲~