| | |
| | | import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
| | | import org.apache.poi.xwpf.usermodel.*; |
| | | import org.openxmlformats.schemas.drawingml.x2006.chart.*; |
| | | import org.openxmlformats.schemas.wordprocessingml.x2006.main.*; |
| | | |
| | | import java.io.FileInputStream; |
| | | import java.io.FileOutputStream; |
| | | import java.io.IOException; |
| | | import java.io.OutputStream; |
| | | import java.math.BigInteger; |
| | | import java.util.*; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | |
| | | textMap.put("P_Impmg11","65"); |
| | | textMap.put("BST1","66"); |
| | | textMap.put("BST2","67"); |
| | | textMap.put("box","1"); |
| | | textMap.put("Box","1"); |
| | | changeChart(document,textMap); |
| | | document.write(os); |
| | | }catch (Exception e){ |
| | |
| | | String selectedPic = EssConfig.getReportTemplates()+"apifanSelected.png"; |
| | | String defaultPic =EssConfig.getReportTemplates()+"apifanDefalut.png"; |
| | | |
| | | //测试用的 |
| | | // String selectedPic = "C:\\测评系统\\home\\reportTemplates\\apifanSelected.png"; |
| | | // String defaultPic ="C:\\测评系统\\home\\reportTemplates\\apifanDefalut.png"; |
| | | |
| | | |
| | | // 遍历段落进行替换操作 |
| | | synchronized (paragraphs) { |
| | | for (XWPFParagraph paragraph : paragraphs) { |
| | |
| | | if (text.contains("{{box0}}")) { // 检查是否包含要替换的文字变量 |
| | | String picturePath = ""; // 图片路径 |
| | | |
| | | String Box = (String) textMap.get("box"); |
| | | String Box = (String) textMap.get("Box"); |
| | | int box = Integer.parseInt(Box); |
| | | if(box== 0) |
| | | { |
| | |
| | | int width = Units.toEMU(20); // 图片宽度 |
| | | int height = Units.toEMU(20); // 图片高度 |
| | | run.addPicture(new FileInputStream(picturePath), pictureType, "image.png", width, height); |
| | | |
| | | // 添加空格或制表符,使文本居中对齐 |
| | | int numberOfSpaces = 3; |
| | | for (int i = 0; i < numberOfSpaces; i++) { |
| | | run.setText(" "); |
| | | } |
| | | // 设置字符间距为居中对齐 |
| | | paragraph.setVerticalAlignment(TextAlignment.CENTER); |
| | | run.setText("结果可信,可以直接解读(测试中未发现明显的“伪装好”倾向)"); |
| | | |
| | | } |
| | | if (text.contains("{{box1}}")) { // 检查是否包含要替换的文字变量 |
| | | String picturePath = ""; // 图片路径 |
| | | |
| | | String Box = (String) textMap.get("box"); |
| | | String Box = (String) textMap.get("Box"); |
| | | int box = Integer.parseInt(Box); |
| | | if(box== 1) |
| | | { |
| | |
| | | int width = Units.toEMU(20); // 图片宽度 |
| | | int height = Units.toEMU(20); // 图片高度 |
| | | run.addPicture(new FileInputStream(picturePath), pictureType, "image.png", width, height); |
| | | // 添加空格或制表符,使文本居中对齐 |
| | | int numberOfSpaces = 3; |
| | | for (int i = 0; i < numberOfSpaces; i++) { |
| | | run.setText(" "); |
| | | } |
| | | // 设置字符间距为居中对齐 |
| | | paragraph.setVerticalAlignment(TextAlignment.CENTER); |
| | | run.setText("结果不可信(测试中有明显的“伪装好”倾向)"); |
| | | |
| | | } |
| | | if (text.contains("{{box2}}")) { // 检查是否包含要替换的文字变量 |
| | | String picturePath = ""; // 图片路径 |
| | | |
| | | String Box = (String) textMap.get("box"); |
| | | String Box = (String) textMap.get("Box"); |
| | | int box = Integer.parseInt(Box); |
| | | if(box== 2) |
| | | { |
| | |
| | | int width = Units.toEMU(20); // 图片宽度 |
| | | int height = Units.toEMU(20); // 图片高度 |
| | | run.addPicture(new FileInputStream(picturePath), pictureType, "image.png", width, height); |
| | | // 添加空格或制表符,使文本居中对齐 |
| | | int numberOfSpaces = 3; |
| | | for (int i = 0; i < numberOfSpaces; i++) { |
| | | run.setText(" "); |
| | | } |
| | | // 设置字符间距为居中对齐 |
| | | paragraph.setVerticalAlignment(TextAlignment.CENTER); |
| | | run.setText("结果可能可信,解读时要谨慎(测试中有一定的“伪装好倾向”)"); |
| | | |
| | | } |