zoukankan      html  css  js  c++  java
  • Excel根据模板生成数据

    就是有个模板,完全保留模板样式的情况下,在相应的地方更改或保留数据

    //参数按顺序分别是模板路径,生成后的文件保存到的路径,替换的内容(键为“行-列”),第几个sheet

    public static void getExcelMB(String pathIn,String pathOut,Map<String, Object> changeMap,int SheetNum) throws IOException{
    Workbook workbook;
    Sheet sheet;
    String bb;

    try {
    Set<String> keySet=changeMap.keySet();
    FileInputStream is=new FileInputStream(pathIn);
    workbook=new HSSFWorkbook(is);
    sheet=(HSSFSheet) workbook.getSheetAt(SheetNum);
    for (String key : keySet) {
    String[] hl=key.split("-");
    Row row=sheet.getRow(Integer.parseInt(hl[0]));
    Cell cell=row.getCell(Integer.parseInt(hl[1]));
    cell.setCellValue(String.valueOf(changeMap.get(key)));
    }

    FileOutputStream fileOut = new FileOutputStream(pathOut);
    workbook.write(fileOut);
    fileOut.close();
    workbook.close();
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
  • 相关阅读:
    Python 循环嵌套
    python 通过序列索引迭代
    Python for 循环语句
    python 无限循环
    Python 循环语句
    Python 条件语句
    Python运算符优先级
    Python身份运算符
    Python成员运算符
    Python逻辑运算符
  • 原文地址:https://www.cnblogs.com/IceBlueBrother/p/8745199.html
Copyright © 2011-2022 走看看