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
40bfdba5
Commit
40bfdba5
authored
Jul 24, 2024
by
韩桐桐
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(jg):告知模板
parent
296f7938
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
8 deletions
+11
-8
WordTemplateUtils.java
...join/amos/boot/module/jg/biz/utils/WordTemplateUtils.java
+11
-8
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 @
40bfdba5
...
...
@@ -20,9 +20,8 @@ import java.io.*;
import
java.nio.charset.StandardCharsets
;
import
java.nio.file.Files
;
import
java.nio.file.Paths
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.UUID
;
import
java.sql.Array
;
import
java.util.*
;
@Slf4j
public
class
WordTemplateUtils
{
...
...
@@ -50,7 +49,7 @@ public class WordTemplateUtils {
* @param template 模板
* @return doc文件
*/
public
static
File
createDoc
(
String
templatePath
,
Map
<
String
,
?
>
dataMap
,
Template
template
)
throws
TemplateException
,
IOException
{
public
static
File
createDoc
(
String
templatePath
,
List
<
Map
<
String
,
?>
>
dataMap
,
Template
template
)
throws
TemplateException
,
IOException
{
// templatePath在后缀之前加上UUID是为了防止并发时多个线程使用同一个模板文件而导致生成的Word文档内容不一致
int
i
=
templatePath
.
lastIndexOf
(
"."
);
templatePath
=
UUID
.
randomUUID
()
+
templatePath
.
substring
(
i
);
...
...
@@ -63,12 +62,16 @@ public class WordTemplateUtils {
// 这个地方不能使用FileWriter因为需要指定编码类型否则生成的Word文档会因为有无法识别的编码而无法打开
Writer
writer
=
new
OutputStreamWriter
(
Files
.
newOutputStream
(
docFile
.
toPath
()),
StandardCharsets
.
UTF_8
)
)
{
template
.
process
(
escapeSpecialCharacters
(
dataMap
),
writer
);
ArrayList
<
Map
<
String
,
Object
>>
arrayList
=
new
ArrayList
<>();
for
(
Map
<
String
,
?>
stringMap
:
dataMap
)
{
arrayList
.
add
(
escapeSpecialCharacters
(
stringMap
));
}
template
.
process
(
arrayList
,
writer
);
}
return
docFile
;
}
public
File
fillAndConvertDocFile
(
String
templatePath
,
String
targetFileName
,
Map
<
String
,
?
>
map
,
int
saveFormat
)
throws
Exception
{
public
File
fillAndConvertDocFile
(
String
templatePath
,
String
targetFileName
,
List
<
Map
<
String
,
?>
>
map
,
int
saveFormat
)
throws
Exception
{
// 指定模板所在包路径
configuration
.
setClassForTemplateLoading
(
this
.
getClass
(),
BASE_PACKAGE_PATH
);
...
...
@@ -154,7 +157,7 @@ public class WordTemplateUtils {
return
url
;
}
public
static
void
templateToPdfDownload
(
String
pdfName
,
String
wordPath
,
Map
<
String
,
Object
>
placeholders
,
HttpServletResponse
response
)
{
public
static
void
templateToPdfDownload
(
String
pdfName
,
String
wordPath
,
List
<
Map
<
String
,
Object
>
>
placeholders
,
HttpServletResponse
response
)
{
// word转pdf
File
pdfFile
;
try
{
...
...
@@ -219,7 +222,7 @@ public class WordTemplateUtils {
*
* @param wordPath word文件路径
*/
private
static
File
wordToPdf
(
String
pdfName
,
String
wordPath
,
Map
<
String
,
Object
>
placeholders
)
throws
Exception
{
private
static
File
wordToPdf
(
String
pdfName
,
String
wordPath
,
List
<
Map
<
String
,
Object
>
>
placeholders
)
throws
Exception
{
Assert
.
hasText
(
wordPath
,
"word文件路径不能为空"
);
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