@Test
public void testExcel() throws IOException {
String toPath = "c:\\STSWorkspace\\ok\\";// 保存新EXCEL路径
String destFilePath = ResourceUtils.getFile("classpath:template/兑付明细模板.xlsx").getPath();
System.out.println("***destFilePath***:"+destFilePath);
File file = new File(destFilePath);
InputStream in = new FileInputStream(destFilePath);
boolean isHSSF = file.getName().endsWith(".xls");//是否是xls
boolean isXSSF = file.getName().endsWith(".xlsx");//是否是xlsx
InputStream inputStream = new FileInputStream(file);
//获取excel的workbook
Workbook workbook = null;
if(isHSSF){
workbook = new HSSFWorkbook(inputStream);
}else if(isXSSF){
workbook = new XSSFWorkbook(inputStream);
}
Sheet sheet = workbook.getSheetAt(0);
FileOutputStream out=new FileOutputStream(toPath + "1.xlsx");
Row row=sheet.getRow(0);
row=sheet.createRow((short)(2));
row.createCell(0).setCellValue("6000000");
out.flush();
workbook.write(out);
out.close();
}