| | |
| | | |
| | | public static void main(String[] args) throws IOException { |
| | | try { |
| | | OutputStream os = new FileOutputStream("C:\\Users\\大头\\Desktop\\MAQ组别报告\\林_PAQ_IA_CN1.docx"); |
| | | /* OutputStream os = new FileOutputStream("C:\\Users\\大头\\Desktop\\MAQ组别报告\\林_PAQ_IA_CN1.docx"); |
| | | XWPFDocument document = new XWPFDocument(POIXMLDocument.openPackage("C:\\Users\\大头\\Desktop\\MAQ组别报告\\终稿【0607中文版】MAQ组别对比报告.docx")); |
| | | |
| | | String fileName = "C:\\Users\\大头\\Desktop\\MAQ组别报告\\MAQ组别导入数据模板.xlsx"; |
| | | //变更图表数据 |
| | | changeMAQTRChart(document,fileName); |
| | | document.write(os); |
| | | document.write(os);*/ |
| | | String fileName = "C:\\Users\\大头\\Desktop\\MAQ组别报告\\组别对比报告测试数据.xlsx"; |
| | | replaceContent(fileName); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 计算数据并生成模板 |
| | | */ |
| | | public static void replaceContent(String fileName){ |
| | | try { |
| | | XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream(fileName)); |
| | | Map<String,Map<Integer,List<Double>>> dataMap = new HashMap<>(); |
| | | for (int i = 0; i < wb.getNumberOfSheets(); i++) { |
| | | XSSFSheet sheet = wb.getSheetAt(i); |
| | | String companyName = sheet.getRow(1).getCell(0).getStringCellValue(); |
| | | Map<Integer,List<Double>> map = new HashMap<>(); |
| | | //行 |
| | | for (int j = 1; j < sheet.getLastRowNum(); j++) { |
| | | XSSFRow row = sheet.getRow(j); |
| | | for (int k = 1; k < row.getLastCellNum(); k++) { |
| | | XSSFCell cell = row.getCell(k); |
| | | /* |
| | | if (CellType.NUMERIC == cell.getCellType()) { |
| | | System.out.println(cell.getNumericCellValue()); |
| | | } else if (CellType.STRING == cell.getCellType()) { |
| | | System.out.println(cell.getStringCellValue()); |
| | | } |
| | | */ |
| | | //table1 多个答题结果处理 |
| | | if(map.get(k) != null){ |
| | | map.get(k).add(cell.getNumericCellValue()); |
| | | }else { |
| | | List<Double> list = new ArrayList<>(); |
| | | list.add(cell.getNumericCellValue()); |
| | | map.put(k,list); |
| | | } |
| | | } |
| | | } |
| | | dataMap.put(companyName,map); |
| | | } |
| | | System.out.println(dataMap); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 初始化报告数据 |
| | | * @param fileName 数据源文件名 |