Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
amos-boot-biz
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
项目统一框架
amos-boot-biz
Commits
923b2211
Commit
923b2211
authored
Jul 24, 2024
by
韩桐桐
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(jg):告知模板回退
parent
40bfdba5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
11 deletions
+8
-11
WordTemplateUtils.java
...join/amos/boot/module/jg/biz/utils/WordTemplateUtils.java
+8
-11
No files found.
amos-boot-system-tzs/amos-boot-module-jg/amos-boot-module-jg-biz/src/main/java/com/yeejoin/amos/boot/module/jg/biz/utils/WordTemplateUtils.java
View file @
923b2211
...
@@ -20,8 +20,9 @@ import java.io.*;
...
@@ -20,8 +20,9 @@ import java.io.*;
import
java.nio.charset.StandardCharsets
;
import
java.nio.charset.StandardCharsets
;
import
java.nio.file.Files
;
import
java.nio.file.Files
;
import
java.nio.file.Paths
;
import
java.nio.file.Paths
;
import
java.sql.Array
;
import
java.util.HashMap
;
import
java.util.*
;
import
java.util.Map
;
import
java.util.UUID
;
@Slf4j
@Slf4j
public
class
WordTemplateUtils
{
public
class
WordTemplateUtils
{
...
@@ -49,7 +50,7 @@ public class WordTemplateUtils {
...
@@ -49,7 +50,7 @@ public class WordTemplateUtils {
* @param template 模板
* @param template 模板
* @return doc文件
* @return doc文件
*/
*/
public
static
File
createDoc
(
String
templatePath
,
List
<
Map
<
String
,
?>
>
dataMap
,
Template
template
)
throws
TemplateException
,
IOException
{
public
static
File
createDoc
(
String
templatePath
,
Map
<
String
,
?
>
dataMap
,
Template
template
)
throws
TemplateException
,
IOException
{
// templatePath在后缀之前加上UUID是为了防止并发时多个线程使用同一个模板文件而导致生成的Word文档内容不一致
// templatePath在后缀之前加上UUID是为了防止并发时多个线程使用同一个模板文件而导致生成的Word文档内容不一致
int
i
=
templatePath
.
lastIndexOf
(
"."
);
int
i
=
templatePath
.
lastIndexOf
(
"."
);
templatePath
=
UUID
.
randomUUID
()
+
templatePath
.
substring
(
i
);
templatePath
=
UUID
.
randomUUID
()
+
templatePath
.
substring
(
i
);
...
@@ -62,16 +63,12 @@ public class WordTemplateUtils {
...
@@ -62,16 +63,12 @@ public class WordTemplateUtils {
// 这个地方不能使用FileWriter因为需要指定编码类型否则生成的Word文档会因为有无法识别的编码而无法打开
// 这个地方不能使用FileWriter因为需要指定编码类型否则生成的Word文档会因为有无法识别的编码而无法打开
Writer
writer
=
new
OutputStreamWriter
(
Files
.
newOutputStream
(
docFile
.
toPath
()),
StandardCharsets
.
UTF_8
)
Writer
writer
=
new
OutputStreamWriter
(
Files
.
newOutputStream
(
docFile
.
toPath
()),
StandardCharsets
.
UTF_8
)
)
{
)
{
ArrayList
<
Map
<
String
,
Object
>>
arrayList
=
new
ArrayList
<>();
template
.
process
(
escapeSpecialCharacters
(
dataMap
),
writer
);
for
(
Map
<
String
,
?>
stringMap
:
dataMap
)
{
arrayList
.
add
(
escapeSpecialCharacters
(
stringMap
));
}
template
.
process
(
arrayList
,
writer
);
}
}
return
docFile
;
return
docFile
;
}
}
public
File
fillAndConvertDocFile
(
String
templatePath
,
String
targetFileName
,
List
<
Map
<
String
,
?>
>
map
,
int
saveFormat
)
throws
Exception
{
public
File
fillAndConvertDocFile
(
String
templatePath
,
String
targetFileName
,
Map
<
String
,
?
>
map
,
int
saveFormat
)
throws
Exception
{
// 指定模板所在包路径
// 指定模板所在包路径
configuration
.
setClassForTemplateLoading
(
this
.
getClass
(),
BASE_PACKAGE_PATH
);
configuration
.
setClassForTemplateLoading
(
this
.
getClass
(),
BASE_PACKAGE_PATH
);
...
@@ -157,7 +154,7 @@ public class WordTemplateUtils {
...
@@ -157,7 +154,7 @@ public class WordTemplateUtils {
return
url
;
return
url
;
}
}
public
static
void
templateToPdfDownload
(
String
pdfName
,
String
wordPath
,
List
<
Map
<
String
,
Object
>
>
placeholders
,
HttpServletResponse
response
)
{
public
static
void
templateToPdfDownload
(
String
pdfName
,
String
wordPath
,
Map
<
String
,
Object
>
placeholders
,
HttpServletResponse
response
)
{
// word转pdf
// word转pdf
File
pdfFile
;
File
pdfFile
;
try
{
try
{
...
@@ -222,7 +219,7 @@ public class WordTemplateUtils {
...
@@ -222,7 +219,7 @@ public class WordTemplateUtils {
*
*
* @param wordPath word文件路径
* @param wordPath word文件路径
*/
*/
private
static
File
wordToPdf
(
String
pdfName
,
String
wordPath
,
List
<
Map
<
String
,
Object
>
>
placeholders
)
throws
Exception
{
private
static
File
wordToPdf
(
String
pdfName
,
String
wordPath
,
Map
<
String
,
Object
>
placeholders
)
throws
Exception
{
Assert
.
hasText
(
wordPath
,
"word文件路径不能为空"
);
Assert
.
hasText
(
wordPath
,
"word文件路径不能为空"
);
WordTemplateUtils
instance
=
WordTemplateUtils
.
getInstance
();
WordTemplateUtils
instance
=
WordTemplateUtils
.
getInstance
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment