根据模板生成带公式的excel

将模板(带公式计算)放在项目路径下某个文件夹

//1.生成工资表excel文件
        FileInputStream fileInputStream = null;
        try {
            fileInputStream = new FileInputStream(request.getServletContext().getRealPath("static/template/工资条模板.xlsx"));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            throw new MyException("找不到工资条模板.xlsx文件");
        }
        XSSFWorkbook excel = null;
        try {
            excel = new XSSFWorkbook(fileInputStream);
        } catch (Exception e) {
            e.printStackTrace();
            throw new MyException("读取文件出错");
        }
        XSSFSheet sheet =  excel.getSheetAt(0);
        //获取模板中的标题
        String title = sheet.getRow(0).getCell(0).getStringCellValue();
        //获取模板中的列名
        String[] rowValue1 = new String[18];
        String[] rowValue2 = new String[3];
        for (int i = 0; i< sheet.getRow(1).getPhysicalNumberOfCells(

你可能感兴趣的:(Java常用工具,excel,公式)