Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
amos-tool
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
tool
amos-tool
Commits
a96cb08a
Commit
a96cb08a
authored
Dec 20, 2023
by
Gwofoo
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/develop' into origin_develop
parents
f7e9fc6c
e9e86137
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
4 additions
and
281 deletions
+4
-281
pom.xml
pom.xml
+2
-2
Application.java
src/main/java/com/yeejoin/amos/Application.java
+2
-1
WordUtil.java
src/main/java/com/yeejoin/amos/api/tool/utils/WordUtil.java
+0
-278
No files found.
pom.xml
View file @
a96cb08a
...
...
@@ -14,6 +14,7 @@
<tyboot-version>
1.1.24-SNAPSHOT
</tyboot-version>
<springboot.version>
2.3.11.RELEASE
</springboot.version>
<springcloud.version>
Hoxton.SR8
</springcloud.version>
<amos.version>
1.9.0-SNAPSHOT
</amos.version>
</properties>
<dependencies>
...
...
@@ -25,7 +26,6 @@
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-netflix-eureka-client
</artifactId>
<version>
3.1.3
</version>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
...
...
@@ -39,7 +39,7 @@
<dependency>
<groupId>
com.yeejoin
</groupId>
<artifactId>
amos-feign-privilege
</artifactId>
<version>
1.8.6
</version>
<version>
${amos.version}
</version>
</dependency>
<!--JSqlparser(高效的SQL解析工具)-->
...
...
src/main/java/com/yeejoin/amos/Application.java
View file @
a96cb08a
...
...
@@ -5,8 +5,8 @@ import org.apache.logging.log4j.Logger;
import
org.mybatis.spring.annotation.MapperScan
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
;
import
org.springframework.cloud.netflix.eureka.EnableEurekaClient
;
import
org.springframework.cloud.openfeign.EnableFeignClients
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.core.env.Environment
;
...
...
@@ -20,6 +20,7 @@ import java.net.InetAddress;
@EnableEurekaClient
@MapperScan
(
value
=
{
"org.typroject.tyboot.*.*.face.orm.dao"
,
"com.yeejoin.amos.api.*.face.orm.dao"
})
@ComponentScan
({
"org.typroject"
,
"com.yeejoin.amos"
})
@EnableFeignClients
@SpringBootApplication
public
class
Application
{
...
...
src/main/java/com/yeejoin/amos/api/tool/utils/WordUtil.java
deleted
100644 → 0
View file @
f7e9fc6c
package
com
.
yeejoin
.
amos
.
api
.
tool
.
utils
;
import
cn.afterturn.easypoi.word.WordExportUtil
;
import
cn.afterturn.easypoi.word.entity.MyXWPFDocument
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONException
;
import
com.alibaba.fastjson.JSONObject
;
import
com.github.abel533.echarts.Option
;
import
com.github.abel533.echarts.code.SelectedMode
;
import
com.github.abel533.echarts.code.Trigger
;
import
com.github.abel533.echarts.data.PieData
;
import
com.github.abel533.echarts.series.Pie
;
import
com.github.abel533.echarts.json.GsonOption
;
//import com.github.abel533.echarts.json.OptionManager;
import
com.spire.doc.*
;
import
com.spire.doc.documents.*
;
import
com.spire.doc.fields.TextRange
;
import
org.apache.poi.xwpf.usermodel.XWPFDocument
;
import
org.typroject.tyboot.core.foundation.utils.ValidationUtil
;
import
java.awt.*
;
import
java.io.*
;
import
java.util.*
;
import
java.util.List
;
/**
* word工具类
*/
public
class
WordUtil
{
/**
* word模板填充数据
*
* @param in 模板地址
* @param data 待填充数据
* @param out 输出流
*/
public
static
void
fillData
(
InputStream
in
,
Map
<
String
,
Object
>
data
,
OutputStream
out
)
throws
Exception
{
try
(
XWPFDocument
myXWPFDocument
=
new
MyXWPFDocument
(
in
);)
{
WordExportUtil
.
exportWord07
(
myXWPFDocument
,
data
);
myXWPFDocument
.
write
(
out
);
}
}
/**
* word填充数据并转为pdf(spire)
*
* @param out 模板地址
* @param data 待填充数据
* @param out 输出地址
*/
public
static
void
fillDataAndToPdfSpire
(
InputStream
in
,
Map
<
String
,
Object
>
data
,
OutputStream
out
)
throws
Exception
{
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
(
5
*
1024
);
WordUtil
.
fillData
(
in
,
data
,
byteArrayOutputStream
);
ByteArrayInputStream
byteArrayInputStream
=
new
ByteArrayInputStream
(
byteArrayOutputStream
.
toByteArray
());
//加载word示例文档
Document
document
=
new
Document
();
document
.
loadFromStream
(
byteArrayInputStream
,
FileFormat
.
Docx
);
//源文件
document
.
saveToStream
(
out
,
FileFormat
.
PDF
);
}
/**
* word填充数据并转为pdf(spire)
*
* @param data 待填充数据
*/
public
static
Document
fillDataAndToPdfSpire1
(
InputStream
in
,
Map
<
String
,
Object
>
data
)
throws
Exception
{
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
(
5
*
1024
);
WordUtil
.
fillData
(
in
,
data
,
byteArrayOutputStream
);
ByteArrayInputStream
byteArrayInputStream
=
new
ByteArrayInputStream
(
byteArrayOutputStream
.
toByteArray
());
//加载word示例文档
Document
document
=
new
Document
();
document
.
loadFromStream
(
byteArrayInputStream
,
FileFormat
.
Docx
);
//源文件
return
document
;
}
/**
* 合并多个word文档
*
* @param ds
*/
public
static
Document
insertContent
(
Document
...
ds
)
{
Document
document
=
new
Document
();
if
(
ds
!=
null
)
{
for
(
int
i
=
0
;
i
<
ds
.
length
;
i
++)
{
Document
di
=
ds
[
i
];
for
(
Object
sectionObj
:
(
Iterable
)
di
.
getSections
())
{
Section
sec
=
(
Section
)
sectionObj
;
//在所有节中循环获取所有子对象
for
(
Object
docObj
:
(
Iterable
)
sec
.
getBody
().
getChildObjects
())
{
DocumentObject
obj
=
(
DocumentObject
)
docObj
;
//获取第一个文档的最后一节
Section
lastSection
=
document
.
getLastSection
();
//将所有子对象添加到第一个文档的最后一节中
Body
body
=
lastSection
.
getBody
();
body
.
getChildObjects
().
add
(
obj
.
deepClone
());
}
}
}
}
return
document
;
}
/**
* 设置表格
*
* @param doc
* @return
*/
private
static
Table
createTable
(
Document
doc
,
JSONObject
object
)
{
JSONObject
data
=
object
.
getJSONObject
(
"data"
);
JSONArray
columns
=
data
.
getJSONArray
(
"columns"
);
JSONArray
rows
=
data
.
getJSONArray
(
"rows"
);
JSONObject
visualParams
=
object
.
getJSONObject
(
"visualParams"
);
Integer
headerMergeIdx
=
data
.
getInteger
(
"headerMergeIdx"
);
// 表头合并数据
Integer
bodyMergeIdx
=
data
.
getInteger
(
"bodyMergeIdx"
);
// 列合并的
Section
section
=
doc
.
addSection
();
Table
table
=
section
.
addTable
(
true
);
// Table table = new Table(true, doc);
if
(
columns
==
null
||
rows
==
null
||
0
==
columns
.
size
())
{
return
table
;
}
int
tableHeaderSize
=
columns
.
size
();
table
.
resetCells
(
rows
.
size
()
+
tableHeaderSize
,
columns
.
getJSONArray
(
0
).
size
());
table
.
autoFit
(
AutoFitBehaviorType
.
Fixed_Column_Widths
);
// region 设置表头
JSONArray
headerLineHeightArray
=
visualParams
.
getJSONArray
(
"headerLineHeight"
);
for
(
int
r
=
0
;
r
<
columns
.
size
();
r
++)
{
//将第一行设置为表格标题
TableRow
row
=
table
.
getRows
().
get
(
r
);
row
.
isHeader
(
true
);
int
finalR
=
r
;
row
.
setHeight
(
Optional
.
ofNullable
(
headerLineHeightArray
).
map
(
o
->
o
.
size
()
>
0
?
o
.
getInteger
(
finalR
)
:
25
).
orElse
(
25
));
row
.
setHeightType
(
TableRowHeightType
.
Exactly
);
row
.
getRowFormat
().
setBackColor
(
Color
.
BLACK
);
for
(
int
i
=
0
;
i
<
columns
.
getJSONArray
(
r
).
size
();
i
++)
{
row
.
getCells
().
get
(
i
).
getCellFormat
().
setVerticalAlignment
(
VerticalAlignment
.
Middle
);
com
.
spire
.
doc
.
documents
.
Paragraph
p
=
row
.
getCells
().
get
(
i
).
addParagraph
();
p
.
getFormat
().
setHorizontalAlignment
(
HorizontalAlignment
.
Center
);
TextRange
txtRange
=
p
.
appendText
(
columns
.
getJSONArray
(
r
).
getString
(
i
));
txtRange
.
getCharacterFormat
().
setBold
(
true
);
txtRange
.
getCharacterFormat
().
setFontSize
(
12
);
txtRange
.
getCharacterFormat
().
setTextColor
(
Color
.
BLUE
);
}
}
// endregion
//将数据添加到其余行
for
(
int
r
=
0
;
r
<
rows
.
size
();
r
++)
{
TableRow
dataRow
=
table
.
getRows
().
get
(
r
+
tableHeaderSize
);
dataRow
.
setHeight
(
25
);
dataRow
.
setHeightType
(
TableRowHeightType
.
Exactly
);
dataRow
.
getRowFormat
().
setBackColor
(
Color
.
white
);
for
(
int
c
=
0
;
c
<
rows
.
getJSONArray
(
r
).
size
();
c
++)
{
int
cellCount
=
dataRow
.
getCells
().
getCount
();
if
(
c
>=
cellCount
)
{
continue
;
}
dataRow
.
getCells
().
get
(
c
).
getCellFormat
().
setVerticalAlignment
(
VerticalAlignment
.
Middle
);
TextRange
textRange
=
dataRow
.
getCells
().
get
(
c
).
addParagraph
().
appendText
(
rows
.
getJSONArray
(
r
).
getString
(
c
));
textRange
.
getCharacterFormat
().
setFontSize
(
12
);
textRange
.
getOwnerParagraph
().
getFormat
().
setHorizontalAlignment
(
HorizontalAlignment
.
Center
);
}
}
if
(!
ValidationUtil
.
isEmpty
(
table
)){
// table.autoFit(AutoFitBehaviorType.Fixed_Column_Widths);
// //列宽自动适应内容
// table.autoFit(AutoFitBehaviorType.Auto_Fit_To_Contents);
// //列宽自动适应窗体
// table.autoFit(AutoFitBehaviorType.Auto_Fit_To_Window);
// //列宽自动适应宽高
// table.autoFit(AutoFitBehaviorType.Fixed_Column_Widths);
}
return
table
;
}
// public static void main(String[] args) {
// //创建Document对象
// Document document = new Document();
//
// //添加节
// Section section = document.addSection();
//
// //添加表格
// Table table = section.addTable();
//
// //设置行数和列数
// table.resetCells(3, 2);
//
// //添加内容到单元格并设置字体
// TextRange textRange = table.get(0, 0).addParagraph().appendText("产品编号");
// textRange.getCharacterFormat().setFontName("宋体");
// textRange = table.get(0, 1).addParagraph().appendText("名称");
// textRange.getCharacterFormat().setFontName("宋体");
// textRange = table.get(1, 0).addParagraph().appendText("T1052");
// textRange.getCharacterFormat().setFontName("宋体");
// textRange = table.get(1, 1).addParagraph().appendText("YT机械键盘(红轴)dsfdfdsfdsfdsfdsfdsfdsfdsfdsfdsfdsfdsfsdfdsffsdfdsfdfdsfdsfdsfsdfsd");
// textRange.getCharacterFormat().setFontName("宋体");
// textRange = table.get(2, 0).addParagraph().appendText("T1062");
// textRange.getCharacterFormat().setFontName("宋体");
// textRange = table.get(2, 1).addParagraph().appendText("WX G41M-P3主板");
// textRange.getCharacterFormat().setFontName("宋体");
//
//
// //列宽自动适应内容
// table.autoFit(AutoFitBehaviorType.Auto_Fit_To_Contents);
// //列宽自动适应窗体
// table.autoFit(AutoFitBehaviorType.Auto_Fit_To_Window);
// //列宽自动适应宽高
// table.autoFit(AutoFitBehaviorType.Fixed_Column_Widths);
//
// //保存文档
// document.saveToFile("D:\\dev\\java\\AutofitToContent.docx", FileFormat.Docx);
// }
// public static void main(String[]args){
//
//// //创建Document对象
// Document document = new Document();
////
//// //添加节
// Section section = document.addSection();
////
//// //添加表格
//
////添加嵌套表格到指定单元格
// Table nestedtable = section.addTable();
////指定嵌套表格行数、列数
// nestedtable.resetCells(4,4);
////设置嵌套表格内容自适应方法
// nestedtable.autoFit(AutoFitBehaviorType.Auto_Fit_To_Contents);
////声明表格数组内容
// String[][] data ={
// new String[]{"编号","产区","最新型号","生产日期",},
// new String[]{"1","A","V2.2.0","2019-06-21"},
// new String[]{"2","B","V2.6.1","2019-06-18"},
// new String[]{"3","C","V2.6.2","2019-06-14"},
// };
////填充数组内容到嵌套表格
// for (int i = 0; i < data.length; i++) {
// TableRow dataRow = nestedtable.getRows().get(i);
// dataRow.getCells().get(i).setWidth(160);
// dataRow.setHeight(25);
// dataRow.setHeightType(TableRowHeightType.Exactly);
// for (int j = 0; j < data[i].length; j++) {
// dataRow.getCells().get(j).getCellFormat().setVerticalAlignment(VerticalAlignment.Middle);
// TextRange range = dataRow.getCells().get(j).addParagraph().appendText(data[i][j]);
// range.getCharacterFormat().setFontName("楷体");
// range.getCharacterFormat().setFontSize(11f);
// range.getOwnerParagraph().getFormat().setHorizontalAlignment(HorizontalAlignment.Center);
// }
// }
////保存文档
// document.saveToFile("D:\\dev\\java\\AutofitToContent.docx", FileFormat.Docx);
// }
public
static
void
main
(
String
[]
args
)
throws
FileNotFoundException
{
Document
document
=
new
Document
();
String
json
=
"{\"visualParams\":{\"headerTextColor\":[\"255 255 255\",\"0 0 0\"],\"headerLineHeight\":[50,50],\"headerBackgroundColor\":[\"75 135 128\",\"255 255 255\"],\"merge\":true,\"bodyLineHeight\":50},\"data\":{\"headerMergeIdx\":5,\"columns\":[[\"火灾事件记录\",\"火灾事件记录\",\"火灾事件记录\",\"火灾事件记录\",\"火灾事件记录\"],[\"序号\",\"着火时间\",\"发生地点(设备)\",\"描述\",\"处置情况\"]],\"rows\":[[\"1\",\"2023-02-03 11:03:38\",\"电脑\",\"1\",\"2\"],[\"2\",\"2023-02-03 14:01:30\",\"test\",\"test\",\"test\"],[\"3\",\"2023-04-23 10:02:43\",\"起火部位\",\"发生经过\",\"责任\"],[\"4\",\"2023-04-23 17:29:01\",\"21312312\",\"321321312312321\",\"321321312\"],[\"5\",\"2023-07-05 14:44:00\",\"cz\",\"1111111111111\",\"333333333\"]]},\"dataConfig\":{\"api\":{\"headers\":[{\"value\":\"52ad02b1-a42a-4330-a6a8-88e61a013aeb\",\"key\":\"token\"},{\"value\":\"AMOS_STUDIO\",\"key\":\"appKey\"},{\"value\":\"AMOS_STUDIO_WEB\",\"key\":\"product\"}],\"reqType\":\"GET\",\"params\":{},\"body\":{},\"url\":\"http://110.42.133.216:9500/idx/platform-report/fire-record\"}}}"
;
Table
table
=
createTable
(
document
,
JSONObject
.
parseObject
(
json
));
document
.
saveToFile
(
"D:\\dev\\java\\AutofitToContent.docx"
,
FileFormat
.
Docx
);
InputStream
fin
=
new
FileInputStream
(
"D:\\dev\\java\\AutofitToContent.docx"
);
OutputStream
os
=
new
FileOutputStream
(
"D:\\dev\\java\\AutofitToContent.pdf"
);
WordToPdf
.
wordTopdfByAspose
(
fin
,
os
,
"pdf"
);
}
}
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