POI3.10读取Excel模板填充数据后生成新的Excel文件

private final DecimalFormat df = new DecimalFormat("#0.00");

    public void test(){
String filePath = "G:\\tmp\\qhjt_yd.xls";
String destPath = "G:\\tmp\\qhjt_yd2.xls"; List<Map<String,Double>> list = getData();
Map<String,String> nsrxx = getBaseInfo(); try {
//读取excel模板
HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(filePath)); //读取第一个工作簿
HSSFSheet sheet = workbook.getSheetAt(0); //设置保留公式
sheet.setForceFormulaRecalculation(true); //定义行与列
HSSFRow row;
HSSFCell cell; //第3行,第2列
row = sheet.getRow(2);
cell = row.getCell(1);
cell.setCellValue(nsrxx.get("nsrmc")); //第3行,第4列
row = sheet.getRow(2);
cell = row.getCell(3);
cell.setCellValue(nsrxx.get("bsq")); //第13行,第3列
row = sheet.getRow(12);
cell = row.getCell(2);
cell.setCellValue(nsrxx.get("ycsm")); //第14行,第2列
row = sheet.getRow(13);
cell = row.getCell(1);
cell.setCellValue(nsrxx.get("tbr")); //第14行,第5列
row = sheet.getRow(13);
cell = row.getCell(4);
cell.setCellValue(nsrxx.get("lxdh")); //从第6行开始读取到第12行
for(int i=5;i<12;i++){
Map<String,Double> mm = list.get(i-5); //获取行
row = sheet.getRow(i); //依次设置3,4列
cell = row.getCell(2);
cell.setCellValue(df.format(mm.get("bq")));
cell = row.getCell(3);
cell.setCellValue(df.format(mm.get("tq")));
} FileOutputStream out = new FileOutputStream(destPath);
workbook.write(out);
out.close();
} catch (IOException ex) {
Logger.getLogger(PoiUtil.class.getName()).log(Level.SEVERE, null, ex);
}
}

POI3.10读取Excel模板填充数据后生成新的Excel文件

上一篇:挖洞姿势:特殊的上传技巧,绕过PHP图片转换实现远程代码执行(RCE)


下一篇:iview table内渲染proptip组件