New file |
| | |
| | | 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(); |
| | | // } |
| | | |
| | | } |
| | | |
| | | } |