Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
midjourney-proxy
Overview
Overview
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
徐少华
midjourney-proxy
Commits
c8b68e59
Commit
c8b68e59
authored
Jun 29, 2021
by
田超
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/1004879' into 'master'
feat: [1004879] 口算批改 See merge request rays/pcloud-common-parent!211
parents
4822c556
60639b81
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
0 deletions
+42
-0
WordUtils.java
...src/main/java/com/pcloud/common/utils/word/WordUtils.java
+42
-0
No files found.
pcloud-common/src/main/java/com/pcloud/common/utils/word/WordUtils.java
View file @
c8b68e59
...
...
@@ -12,6 +12,7 @@ import java.net.MalformedURLException;
import
java.net.URL
;
import
java.util.List
;
import
com.lowagie.text.Rectangle
;
import
org.apache.poi.POIXMLDocument
;
import
org.apache.poi.openxml4j.exceptions.InvalidFormatException
;
import
org.apache.poi.openxml4j.opc.OPCPackage
;
...
...
@@ -107,6 +108,44 @@ public class WordUtils {
return
outPath
;
}
public
static
String
create
(
List
<
WordPO
>
wordPOs
,
Integer
width
,
Integer
height
)
throws
FileException
{
LOGGER
.
info
(
"【WORD】创建自定义尺寸WORD文档,<START>"
);
if
(
ListUtils
.
isEmpty
(
wordPOs
))
{
return
null
;
}
String
outPath
=
null
;
Document
document
=
null
;
OutputStream
os
=
null
;
RtfWriter2
rtfWriter2
=
null
;
try
{
// 输出路径
outPath
=
FilePathConstant
.
WORD
+
UUIDUitl
.
taskName
()
+
".doc"
;
FileUtils
.
creatFiles
(
outPath
);
// 创建输出流
os
=
new
FileOutputStream
(
new
File
(
outPath
));
// 初始化文档
// 创建文档实例
// 创建word文档,并设置纸张的大小
float
rate
=
2.83333f
;
width
=
Math
.
round
(
width
*
rate
);
height
=
Math
.
round
(
height
*
rate
);
document
=
new
Document
(
new
Rectangle
(
width
,
height
));
rtfWriter2
=
RtfWriter2
.
getInstance
(
document
,
os
);
document
.
open
();
// 添加内容添加PDF实例中
addChunks
(
wordPOs
,
document
);
}
catch
(
Exception
e
)
{
FileUtils
.
deleteFile
(
outPath
);
LOGGER
.
error
(
"【WORD】创建WORD文档失败:"
+
e
.
getMessage
(),
e
);
throw
new
FileException
(
FileException
.
FILE_CONTENT_ERROR
,
e
.
getMessage
());
}
finally
{
close
(
document
,
os
,
rtfWriter2
);
}
LOGGER
.
info
(
"【WORD】创建WORD文档,<END>"
);
return
outPath
;
}
/**
* 添加内容到PDF中
*
...
...
@@ -142,6 +181,9 @@ public class WordUtils {
// 段落
Paragraph
paragraph
=
null
;
Font
font
=
WordFontUtils
.
getByType
(
wordChunkPO
.
getFont
());
if
(
wordChunkPO
.
getFontSize
()
>
0
)
{
font
.
setSize
(
wordChunkPO
.
getFontSize
());
}
if
(
wordChunkPO
.
isLeanding
())
{
paragraph
=
new
Paragraph
(
wordChunkPO
.
getText
(),
font
);
paragraph
.
setLeading
(
wordChunkPO
.
getLeading
()
>
0
?
wordChunkPO
.
getLeading
()
:
Float
.
NaN
);
...
...
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