Commit 9a2f9b4c authored by miko's avatar miko

Initial commit

parents
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.4/apache-maven-3.9.4-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar
This source diff could not be displayed because it is too large. You can view the blob instead.
File added
This diff is collapsed.
This diff is collapsed.
File added
This diff is collapsed.
@REM ----------------------------------------------------------------------------
@REM Licensed to the Apache Software Foundation (ASF) under one
@REM or more contributor license agreements. See the NOTICE file
@REM distributed with this work for additional information
@REM regarding copyright ownership. The ASF licenses this file
@REM to you under the Apache License, Version 2.0 (the
@REM "License"); you may not use this file except in compliance
@REM with the License. You may obtain a copy of the License at
@REM
@REM https://www.apache.org/licenses/LICENSE-2.0
@REM
@REM Unless required by applicable law or agreed to in writing,
@REM software distributed under the License is distributed on an
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@REM KIND, either express or implied. See the License for the
@REM specific language governing permissions and limitations
@REM under the License.
@REM ----------------------------------------------------------------------------
@REM ----------------------------------------------------------------------------
@REM Apache Maven Wrapper startup batch script, version 3.2.0
@REM
@REM Required ENV vars:
@REM JAVA_HOME - location of a JDK home dir
@REM
@REM Optional ENV vars
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
@REM e.g. to debug Maven itself, use
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
@REM ----------------------------------------------------------------------------
@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
@echo off
@REM set title of command window
title %0
@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on'
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
@REM set %HOME% to equivalent of $HOME
if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
@REM Execute a user defined script before this one
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
@REM check for pre script, once with legacy .bat ending and once with .cmd ending
if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %*
if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %*
:skipRcPre
@setlocal
set ERROR_CODE=0
@REM To isolate internal variables from possible post scripts, we use another setlocal
@setlocal
@REM ==== START VALIDATION ====
if not "%JAVA_HOME%" == "" goto OkJHome
echo.
echo Error: JAVA_HOME not found in your environment. >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
:OkJHome
if exist "%JAVA_HOME%\bin\java.exe" goto init
echo.
echo Error: JAVA_HOME is set to an invalid directory. >&2
echo JAVA_HOME = "%JAVA_HOME%" >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
@REM ==== END VALIDATION ====
:init
@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
@REM Fallback to current working directory if not found.
set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
set EXEC_DIR=%CD%
set WDIR=%EXEC_DIR%
:findBaseDir
IF EXIST "%WDIR%"\.mvn goto baseDirFound
cd ..
IF "%WDIR%"=="%CD%" goto baseDirNotFound
set WDIR=%CD%
goto findBaseDir
:baseDirFound
set MAVEN_PROJECTBASEDIR=%WDIR%
cd "%EXEC_DIR%"
goto endDetectBaseDir
:baseDirNotFound
set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
cd "%EXEC_DIR%"
:endDetectBaseDir
IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
@setlocal EnableExtensions EnableDelayedExpansion
for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
:endReadAdditionalConfig
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
set WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar"
FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
IF "%%A"=="wrapperUrl" SET WRAPPER_URL=%%B
)
@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
@REM This allows using the maven wrapper in projects that prohibit checking in binary data.
if exist %WRAPPER_JAR% (
if "%MVNW_VERBOSE%" == "true" (
echo Found %WRAPPER_JAR%
)
) else (
if not "%MVNW_REPOURL%" == "" (
SET WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar"
)
if "%MVNW_VERBOSE%" == "true" (
echo Couldn't find %WRAPPER_JAR%, downloading it ...
echo Downloading from: %WRAPPER_URL%
)
powershell -Command "&{"^
"$webclient = new-object System.Net.WebClient;"^
"if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^
"$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^
"}"^
"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%WRAPPER_URL%', '%WRAPPER_JAR%')"^
"}"
if "%MVNW_VERBOSE%" == "true" (
echo Finished downloading %WRAPPER_JAR%
)
)
@REM End of extension
@REM If specified, validate the SHA-256 sum of the Maven wrapper jar file
SET WRAPPER_SHA_256_SUM=""
FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
IF "%%A"=="wrapperSha256Sum" SET WRAPPER_SHA_256_SUM=%%B
)
IF NOT %WRAPPER_SHA_256_SUM%=="" (
powershell -Command "&{"^
"$hash = (Get-FileHash \"%WRAPPER_JAR%\" -Algorithm SHA256).Hash.ToLower();"^
"If('%WRAPPER_SHA_256_SUM%' -ne $hash){"^
" Write-Output 'Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised.';"^
" Write-Output 'Investigate or delete %WRAPPER_JAR% to attempt a clean download.';"^
" Write-Output 'If you updated your Maven version, you need to update the specified wrapperSha256Sum property.';"^
" exit 1;"^
"}"^
"}"
if ERRORLEVEL 1 goto error
)
@REM Provide a "standardized" way to retrieve the CLI args that will
@REM work with both Windows and non-Windows executions.
set MAVEN_CMD_LINE_ARGS=%*
%MAVEN_JAVA_EXE% ^
%JVM_CONFIG_MAVEN_PROPS% ^
%MAVEN_OPTS% ^
%MAVEN_DEBUG_OPTS% ^
-classpath %WRAPPER_JAR% ^
"-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^
%WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
if ERRORLEVEL 1 goto error
goto end
:error
set ERROR_CODE=1
:end
@endlocal & set ERROR_CODE=%ERROR_CODE%
if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost
@REM check for post script, once with legacy .bat ending and once with .cmd ending
if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat"
if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd"
:skipRcPost
@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
if "%MAVEN_BATCH_PAUSE%"=="on" pause
if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE%
cmd /C exit /B %ERROR_CODE%
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>radiometer-management</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>radiometer-management</name>
<description>radiometer-management</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.deepoove</groupId>
<artifactId>poi-tl</artifactId>
<version>1.12.0</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.14.2</version>
</dependency>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose</artifactId>
<version>19</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<groupId>com.aspose</groupId>
<artifactId>aspose</artifactId>
<version>19</version>
<packaging>jar</packaging>
<file>${basedir}/lib/aspose-words.jar</file>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<verbose>true</verbose>
</configuration>
</plugin>
</plugins>
</build>
</project>
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Demo3Application {
public static void main(String[] args) {
SpringApplication.run(Demo3Application.class, args);
}
}
\ No newline at end of file
package com.example.demo;
import java.io.File;
public class GetWebProjectRealPathTool {
/**
* 获取项目在服务其中的真实路径的工具类
* 这是在web项目中,获取项目实际路径的最佳方式,在windows和linux系统下均可正常使用
*/
public static String getRootPath() {
return System.getProperty("user.dir");
}
public static String getRootPath1(){
/**
* 方法一:获取当前可执行jar包所在目录
*/
String filePath = System.getProperty("java.class.path");
String pathSplit = System.getProperty("path.separator");//得到当前操作系统的分隔符,windows下是";",linux下是":"
/**
* 若没有其他依赖,则filePath的结果应当是该可运行jar包的绝对路径,
* 此时我们只需要经过字符串解析,便可得到jar所在目录
*/
if(filePath.contains(pathSplit)){
filePath = filePath.substring(0,filePath.indexOf(pathSplit));
}else if (filePath.endsWith(".jar")) {//截取路径中的jar包名,可执行jar包运行的结果里包含".jar"
filePath = filePath.substring(0, filePath.lastIndexOf(File.separator) + 1);
}
return filePath;
}
}
package com.example.demo;
import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.data.*;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.xwpf.usermodel.*;
import org.apache.xmlbeans.XmlCursor;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.nodes.Node;
import org.jsoup.select.Elements;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
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 {
// 模拟获取前端传输过来的base64
String text = new String(Files.readAllBytes(Paths.get(GetWebProjectRealPathTool.getRootPath() + "/abc.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()) {
if (child.nodeName().equals("img")) {
// 这是一个<img>标签,处理图片
String src = child.attr("src");
if (src.contains("base64,")) {
of.addParagraph(Paragraphs.of(Pictures.ofBase64(src, PictureType.PNG).create()).create());
}
} else if (child.nodeName().equals("#text")) {
// 这是一个文本节点,处理文本
String t = child.toString().trim();
if (!t.isEmpty()) {
of.addParagraph(Paragraphs.of(t.replace("&nbsp;", " ")).create());
}
}
}
} else if (element.tagName().equals("table")) {
// 新代码:处理表格
TableRenderData tableData = parseTable(element);
of.addTable(tableData);
}
}
// 初始数据create
DocumentRenderData data = of.create();
XWPFTemplate orignTemplate = XWPFTemplate.create(data);
// ----定位后插入
// 加载模板
XWPFTemplate template = XWPFTemplate.compile(GetWebProjectRealPathTool.getRootPath() + "/ccmuJsfw.docx");
XWPFDocument document = template.getXWPFDocument();
// 定位到特定位置,例如在"审计抽查)"后面插入段落
List<XWPFParagraph> paragraphs = document.getParagraphs();
XWPFParagraph targetPara = null;
for (XWPFParagraph paragraph : paragraphs) {
if (paragraph.getText().contains("审计抽查)")) {
targetPara = paragraph;
break;
}
}
XmlCursor cursor = targetPara.getCTP().newCursor();
List<IBodyElement> iBodyElements = orignTemplate.getXWPFDocument().getBodyElements();
for (IBodyElement e : iBodyElements) {
if (e.getElementType().toString().equals("PARAGRAPH")) {
XWPFParagraph paragraph = (XWPFParagraph) e;
cursor.toEndToken(); // 移动到当前段落的末尾
cursor.toNextToken(); // 移动到下一个元素
XWPFParagraph newParagraph = document.insertNewParagraph(cursor);
List<XWPFRun> runs = paragraph.getRuns();
for (XWPFRun r : runs) {
if ("".equals(r.text()) && r.getEmbeddedPictures().size() == 0) {
continue;
}
XWPFRun run = newParagraph.createRun();
// 设置字体大小(以半点为单位,所以 28 对应 14pt)
run.setFontSize(12);
run.setBold(true);
run.setFontFamily("宋体");
run.setText(r.text());
// 在当前位置创建新段落
if (r.getEmbeddedPictures() != null) {
for (XWPFPicture pic : r.getEmbeddedPictures()) {
InputStream picStream = pic.getPictureData().getPackagePart().getInputStream();
int format = pic.getPictureData().getPictureType();
// 从源Run获取图片的宽度和高度
long width = pic.getCTPicture().getSpPr().getXfrm().getExt().getCx();
long height = pic.getCTPicture().getSpPr().getXfrm().getExt().getCy();
run = newParagraph.createRun();
// 将图片复制到目标Run
run.addPicture(picStream, format, "image" + pic.getPictureData().getFileName(), (int) width, (int) height);
}
}
}
} else if (e.getElementType().toString().equals("TABLE")) {
XWPFTable table = (XWPFTable) e;
cursor.toEndToken(); // 移动到当前段落的末尾
cursor.toNextToken(); // 移动到下一个元素
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");
} catch (IOException e) {
e.printStackTrace();
} finally {
if (template != null) {
try {
template.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
private static TableRenderData parseTable(Element table) {
Elements rows = table.select("tr");
int rowCount = rows.size();
int colCount = rows.get(0).select("th, td").size();
String[][] cellTexts = new String[rowCount][colCount];
for (int r = 0; r < rowCount; r++) {
Elements cells = rows.get(r).select("th, td");
for (int c = 0; c < cells.size(); c++) {
cellTexts[r][c] = cells.get(c).text();
}
}
return Tables.of(cellTexts).create();
}
}
package com.example.demo;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
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);
}
}
}
System.out.println(doc.body().html());
}
}
This diff is collapsed.
package com.example.demo;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class Demo3ApplicationTests {
@Test
void contextLoads() {
}
}
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