[测评系统]--测评系统核心代码库
吴祝攀
2024-06-14 499b1d27da156ddd25c7adb58a5601805d8149fe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package com.ots.project.tool.report.LAQ.chart;
 
import com.alibaba.fastjson.JSON;
import com.microsoft.schemas.vml.CTTextbox;
import com.ots.common.utils.poi.ExcelUtil;
import com.ots.common.utils.poi.WordUtil;
import com.ots.project.tool.report.LAQ.LAQReport;
import com.ots.project.tool.report.LAQ.LAQTemplate;
import com.ots.project.tool.report.MAQ.base.SeriesData;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;
 
import java.awt.*;
import java.io.*;
import java.math.BigInteger;
import java.util.*;
 
 
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
 
@Slf4j
public class LAQTest {
    public static void main(String[] args) throws Exception {
        System.out.println("启动测试..");
 
 
//
//        try {
//            FileInputStream fis = new FileInputStream("D:\\桌面文件\\TaiTest.docx");
//            XWPFDocument document = new XWPFDocument(fis);
//
//            List<XWPFParagraph> paragraphs = document.getParagraphs();
//            for (XWPFParagraph paragraph : paragraphs) {
//                for (XWPFRun run : paragraph.getRuns()) {
//                    for (XWPFPicture picture : run.getEmbeddedPictures()) {
//                        if (picture.getCTPicture() != null
//                                && picture.getCTPicture().getSpPr() != null
//                                && picture.getCTPicture().getSpPr().getXfrm() != null
//                                && picture.getCTPicture().getSpPr().getXfrm().getExt() != null) {
//
//                            CTPositiveSize2D ext = picture.getCTPicture().getSpPr().getXfrm().getExt();
//                            if (ext != null) {
//                                long widthEmus = ext.getCx();
//                                long heightEmus = ext.getCy();
//
//                                int width = (int) (widthEmus / 9525); // Convert EMUs to points (assuming 1 inch = 9525 EMUs)
//                                int height = (int) (heightEmus / 9525); // Convert EMUs to points (assuming 1 inch = 9525 EMUs)
//
//                                System.out.println("Image Width: " + width + " points");
//                                System.out.println("Image Height: " + height + " points");
//                            }
//                        } else {
//                            System.err.println("Error: Unable to retrieve image width and height.");
//                        }
//                    }
//                }
//            }
//
//
//            // 创建一个新的段落
////            XWPFParagraph paragraph = document.createParagraph();
////
////            // 设置段落的左边距和上边距
//////            paragraph.setIndentationLeft(0); // 0最小。7500
//////            paragraph.setSpacingBefore(0); // 设置上边距为0
////            paragraph.setIndentationLeft(7200);//最大8000
////            paragraph.setSpacingBefore(7000);//最大7200
////
////            // 添加文本到段落
////            XWPFRun run = paragraph.createRun();
////            run.setText("吴祝攀");
////
////
////            XWPFParagraph paragraph1 = document.createParagraph();
////            paragraph1.setIndentationLeft(5000);//最大8000
////            paragraph1.setSpacingBefore(5000);//最大7200
////            XWPFRun run1= paragraph1.createRun();
////            run1.setText("吴语晨");
//
//
//            // 创建一个形状作为文本框
//            Shape textBox = new Shape(document, ShapeType.TEXT_BOX);
//
//            // 设置文本框的内容
//            textBox.getTextPath().setText("文本框中的文本");
//
//            // 设置文本框的位置和大小
//            textBox.setWidth(200); // 设置宽度
//            textBox.setHeight(100); // 设置高度
//
//            // 设置文本框的背景透明
//            textBox.setFilled(false); // 设置填充色为透明
//            textBox.setStrokeColor(Color.WHITE); // 设置边框颜色为透明
//
//            // 将文本框添加到文档中
//            doc.getFirstSection().getBody().getFirstParagraph().appendChild(textBox);
//
//
//            // 将文档写入到文件
//            FileOutputStream fos = new FileOutputStream("D:\\桌面文件\\TaiTest_out_"+ UUID.randomUUID().toString() +".docx");
//            document.write(fos);
//
//            // 关闭文件流
//            fis.close();
//            fos.close();
//
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//
 
//        FileInputStream fis = new FileInputStream("D:\\桌面文件\\TaiTest.docx");
//        Document doc = new Document(fis);
//
//        // 创建文本框
//        Shape textBox = new Shape(doc, ShapeType.TEXT_BOX);
//        textBox.setWidth(200); // 设置文本框宽度
//        textBox.setHeight(50); // 设置文本框高度
//        textBox.setWrapType(WrapType.NONE); // 设置文本框不自动换行
//
//        // 创建文本框的段落和Run对象,并添加内容
//        Paragraph para = new Paragraph(doc);
//        Run run = new Run(doc, "这是文本框中的内容");
//        para.appendChild(run);
//        textBox.appendChild(para);
//
//        // 添加文本框到Word文档
//        doc.getFirstSection().getBody().getFirstParagraph().appendChild(textBox);
//
//        // 保存修改后的Word文档
//        doc.save("D:\\桌面文件\\TaiTest_out_"+ UUID.randomUUID().toString() +".docx");
//
 
        // 创建一个空的Word文档
//        XWPFDocument document = new XWPFDocument();
//
//        // 创建一个段落
//        XWPFParagraph paragraph = document.createParagraph();
//
//        // 创建一个文本框
//        XWPFRun run = paragraph.createRun();
//        CTTextbox textbox = run.getCTR().addNewTextbox();
//        CTTextboxContent textboxContent = textbox.addNewTextboxContent();
//
//        // 设置文本框的位置和大小
//        textbox.setInset(new BigInteger("0"));
//        textboxContent.setWMode(STTextbox.WMode.WINDOW);
//        textboxContent.setNoBorder(true);
//        textboxContent.setAnchor(STTextAnchoringType.MIDDLE);
//        textboxContent.setAnchorCenter(true);
//
//        // 设置文本框的内容
//        textboxContent.setT("This is a text box.");
//
//        // 保存文档
//        try {
//            FileOutputStream out = new FileOutputStream("example.docx");
//            document.write(out);
//            out.close();
//            System.out.println("Word文档创建成功!");
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
 
    }
 
}