Commit 1cbd0b30 authored by miko's avatar miko

init

parent 9a2f9b4c
Pipeline #51 canceled with stages
This diff is collapsed.
No preview for this file type
No preview for this file type
......@@ -18,24 +18,26 @@ import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
public class InsertAtPositionExample {
public static void main(String[] args) throws IOException, InvalidFormatException {
public static void main(String[] args) throws Exception {
String fileName = "样例1";
// 模拟获取前端传输过来的base64
String text = new String(Files.readAllBytes(Paths.get(GetWebProjectRealPathTool.getRootPath() + "/abc.txt")), StandardCharsets.UTF_8);
String text = new String(Files.readAllBytes(Paths.get(GetWebProjectRealPathTool.getRootPath() + "/"+fileName+".txt")), StandardCharsets.UTF_8);
Document orignDocument = Jsoup.parseBodyFragment(text);
Documents.DocumentBuilder of = Documents.of();
Elements links = orignDocument.getElementsByTag("p");
Elements allElements = orignDocument.body().children();
// 遍历插入到临时的段落里
for (Element element : allElements) {
if (element.tagName().equals("p")) {
for (Node child : element.childNodes()) {
System.out.println(child.nodeName());
if (child.nodeName().equals("img")) {
// 这是一个<img>标签,处理图片
String src = child.attr("src");
......@@ -48,6 +50,19 @@ public class InsertAtPositionExample {
if (!t.isEmpty()) {
of.addParagraph(Paragraphs.of(t.replace("&nbsp;", " ")).create());
}
}else{
// 检查该节点是否为Element类型
if (child instanceof Element) {
Element strongElement = (Element) child;
// 获取标签内的文本
String t = strongElement.text();
if (!t.isEmpty()) {
of.addParagraph(Paragraphs.of(t.replace("&nbsp;", " ")).create());
}
}
}
}
} else if (element.tagName().equals("table")) {
......@@ -99,13 +114,13 @@ public class InsertAtPositionExample {
continue;
}
XWPFRun run = newParagraph.createRun();
// 设置字体大小(以半点为单位,所以 28 对应 14pt)
run.setFontSize(12);
run.setBold(true);
run.setFontFamily("宋体");
run.setText(r.text());
// XWPFRun run = newParagraph.createRun();
// // 设置字体大小(以半点为单位,所以 28 对应 14pt)
// run.setFontSize(12);
// run.setBold(true);
// run.setFontFamily("宋体");
// run.setText(r.text());
// 在当前位置创建新段落
if (r.getEmbeddedPictures() != null) {
......@@ -118,11 +133,13 @@ public class InsertAtPositionExample {
long width = pic.getCTPicture().getSpPr().getXfrm().getExt().getCx();
long height = pic.getCTPicture().getSpPr().getXfrm().getExt().getCy();
run = newParagraph.createRun();
XWPFRun run = newParagraph.createRun();
// 将图片复制到目标Run
run.addPicture(picStream, format, "image" + pic.getPictureData().getFileName(), (int) width, (int) height);
}
}else{
newParagraph.addRun(r);
}
}
} else if (e.getElementType().toString().equals("TABLE")) {
......@@ -135,44 +152,24 @@ public class InsertAtPositionExample {
XWPFTable newXWPFTable = document.insertNewTbl(cursor);
newXWPFTable.removeRow(0);
System.out.println(">>>>>>>>>>>");
System.out.println(table.getRows().size());
System.out.println(table.getRows().get(0).getTableCells().size());
// 遍历旧表格
for (int i = 0;i< table.getRows().size();i++) {
XWPFTableRow srcTableRow = table.getRows().get(i);
// 创建新行
// XWPFTableRow newRow = newXWPFTable.createRow();
newXWPFTable.addRow(srcTableRow, i);
// 你可能需要调整行高,字体等行级属性
// newRow.setHeight(srcTableRow.getHeight());
// // 遍历所有单元格
// for (int j = 0; j < srcTableRow.getTableCells().size(); j++) {
// // 获取旧单元格的数据
// String t = srcTableRow.getCell(j).getText();
//
// // 创建新单元格并添加数据
// newRow.createCell().setText(t);
// }
}
System.out.println(">>>>>>>>>>>");
System.out.println(newXWPFTable.getRows().size());
System.out.println(newXWPFTable.getRows().get(0).getTableCells().size());
}
}
// 保存修改后的文档
try {
template.writeToFile(GetWebProjectRealPathTool.getRootPath() + "/path_to_output.docx");
template.writeToFile(GetWebProjectRealPathTool.getRootPath() + "/path_to_output"+fileName+".docx");
} catch (IOException e) {
e.printStackTrace();
} finally {
......
package com.example.demo;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import com.aspose.words.*;
import com.aspose.words.Shape;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.awt.*;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
public class Main {
public static void main(String[] args) {
String html = "<p>xxxx<img />hdhsafahh</p><p>fadfadf</p><p><img /><p>";
Document doc = Jsoup.parseBodyFragment(html);
// 选择所有的<p>标签
Elements pTags = doc.select("p");
for (Element p : pTags) {
Elements imgTags = p.select("img");
if (imgTags.size() > 0) {
for (Element img : imgTags) {
// 创建新的<p>标签并包裹<img>
Element newPTag = new Element("p");
img.replaceWith(newPTag);
newPTag.appendChild(img);
public static void main(String[] args) throws Exception {
String fileName = "样例1";
// 模拟获取前端传输过来的base64
// 打开现有的Word文档
Document doc = new Document(GetWebProjectRealPathTool.getRootPath() + "/"+"ccmuJsfw.docx");
// 创建FindReplaceOptions对象
FindReplaceOptions options = new FindReplaceOptions();
options.setReplacingCallback(new IReplacingCallback() {
@Override
public int replacing(ReplacingArgs e) throws Exception {
// 创建一个DocumentBuilder并将其光标移至匹配节点的位置
DocumentBuilder builder = new DocumentBuilder((Document) e.getMatchNode().getDocument());
builder.moveTo(e.getMatchNode());
String html = new String(Files.readAllBytes(Paths.get(GetWebProjectRealPathTool.getRootPath() + "/"+fileName+".txt")), StandardCharsets.UTF_8);
builder.insertHtml(html);
// 告诉引擎我们已经替换了文本,跳过默认的替换动作
return ReplaceAction.SKIP;
}
});
// 执行查找和替换
doc.getRange().replace("{{协议信息}}", "", options);
insertWatermarkText(doc, "CCMU");
doc.save(GetWebProjectRealPathTool.getRootPath() + "/"+"output"+fileName+".docx");
//
// Document doc = new Document("path/to/your/document.docx");
}
private static void insertWatermarkText(Document doc, String watermarkText) throws Exception {
// Create a watermark shape.
Shape watermark = new Shape(doc, ShapeType.TEXT_PLAIN_TEXT);
// Set various properties for the shape.
watermark.getTextPath().setText(watermarkText);
watermark.getTextPath().setFontFamily("Arial");
watermark.setWidth(300);
watermark.setHeight(80);
watermark.setRotation(-40); // Rotate the text
watermark.getFill().setColor(Color.GRAY); // Try other color combinations if you want
watermark.setStrokeColor(Color.GRAY);
// Place the watermark in the page center.
watermark.setRelativeHorizontalPosition(RelativeHorizontalPosition.PAGE);
watermark.setRelativeVerticalPosition(RelativeVerticalPosition.PAGE);
watermark.setWrapType(WrapType.NONE);
watermark.setVerticalAlignment(VerticalAlignment.CENTER);
watermark.setHorizontalAlignment(HorizontalAlignment.CENTER);
// Create a new paragraph and append the watermark to this paragraph.
Paragraph watermarkPara = new Paragraph(doc);
watermarkPara.appendChild(watermark);
// Insert the watermark into all headers of each section.
for (Section sect : doc.getSections()) {
// There could be up to three different headers in each section, so we insert the watermark into all of them.
insertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HEADER_PRIMARY);
insertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HEADER_FIRST);
insertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HEADER_EVEN);
}
}
private static void insertWatermarkIntoHeader(Paragraph watermarkPara, Section sect, int headerType) throws Exception {
HeaderFooter header = sect.getHeadersFooters().getByHeaderFooterType(headerType);
if (header == null) {
// There is no header of the specified type in the current section, create it.
header = new HeaderFooter(sect.getDocument(), headerType);
sect.getHeadersFooters().add(header);
}
System.out.println(doc.body().html());
// Insert a clone of the watermark into the header.
header.appendChild(watermarkPara.deepClone(true));
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
<p><br></p><table style=""><tbody><tr><td colSpan="1" rowSpan="1"></td><td colSpan="1" rowSpan="1">具体分析内容</td><td colSpan="1" rowSpan="1">备注</td></tr><tr><td colSpan="1" rowSpan="1">分析内容</td><td colSpan="1" rowSpan="1">标准分析内容&nbsp;序列优化及质控&nbsp;测序数据介绍&nbsp;数据过滤及质量评估&nbsp;划分&nbsp;OTU&nbsp;OTU&nbsp;生成&nbsp;OTU&nbsp;聚类结果统计&nbsp;OTU&nbsp;丰度统计&nbsp;分类学分析&nbsp;物种分类与相对丰度统计&nbsp;群落结构分析&nbsp;物种热图分析(N≥3)&nbsp;物种系统进化分析&nbsp;单样品分类学树状图&nbsp;分析内容&nbsp;多样品分类学树状图&nbsp;单样品(alpha)多样性分析&nbsp;a-多样性指数统计&nbsp;高级分析内容&nbsp;组间差异分析(分组≥2,每组≥2样品)&nbsp;LEfSe&nbsp;分析&nbsp;组间显著性差异分析&nbsp;样品间相关分析(N≥3)&nbsp;三元相图(N≥3)&nbsp;Anova方差分析(分组≥2,每组≥2样品)&nbsp;Wilcox秩和检验(分组≥2,每组≥2样品)&nbsp;RDA/CCA分析(属水平)(注:需要提供环境因子数据,&nbsp;且环境因子数小于分析样品数)&nbsp;基于16S的COG和KEGG数据库功能富集(限细菌)</td><td colSpan="1" rowSpan="1"></td></tr><tr><td colSpan="1" rowSpan="1">售后服务</td><td colSpan="1" rowSpan="1">甲方可以在分析完成日后的三个月内针对原有数据、结果、分析方法等方面的疑问咨询乙方,乙方在一个月内给甲方提供整理分析类服务,三个月内提供问题解答服务,咨询范围只限于合同中的服务内容。</td><td colSpan="1" rowSpan="1"></td></tr><tr><td colSpan="3" rowSpan="1">注:1、待项目启动后20天未提供分析方案,将按不分组进行分析出具报告。待&nbsp;老师出具方案后再进行免费个性化分析。乙方提供给甲方的分析内容以合同为&nbsp;准,任何口头承诺均无效。&nbsp;2、每批样本分析次数不超过3次。</td></tr></tbody></table><p style="text-indent: 0cm; line-height: 150%;"><span style="font-size: 12pt; font-family: 宋体;">1.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;考核指标及验收方式:</span></p><p style="text-indent: 20.9pt; line-height: 150%;"><span style="font-size: 12pt; font-family: 宋体;">试验全部完成后,受委托方按合同规定的内容向委托方提供全部试验原始资料,图片和电子数据表(含计算方法及相关软件信息)等。并出具相应的试验报告(电子版与盖章纸质版),并保证报告的真实性、准确性、科学性,同时对全部资料有保密责任。项目完成后,受委托方应当将项目相关的原始记录、原始数据归档保存。</span></p><p style="text-indent: 0cm; line-height: 150%;"><span style="font-size: 12pt; font-family: 宋体;">2.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;技术服务地点:北京百迈客生物科技有限公司</span></p><p style="text-indent: 0cm; line-height: 150%;"><span style="font-size: 12pt; font-family: 宋体;">3.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;标分析技术务期:30自然(n≤24)(不包含定制化分析周期)。自乙方收到首付款且样本质检合格次日起到乙方向甲方提供《结题报告》或《标准分析报告》之日止。若在项目生产过程中遇到技术障碍,乙方应与甲方及时沟通,&nbsp;双方沟通时间。</span></p>
\ No newline at end of file
<p style="text-indent: -21.25pt; line-height: 150%;"><strong>1.&nbsp;&nbsp;</strong><span style="font-family: 宋体;"><strong>主要内容</strong></span></p>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment