Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
datax-common
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
黄营
datax-common
Commits
633c69bc
Commit
633c69bc
authored
Jan 25, 2024
by
hy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
集成common-office模块
parent
36b0b886
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
176 additions
and
1 deletions
+176
-1
pom.xml
pom.xml
+12
-1
MapMailMergeDataSource.java
...va/cn/datax/commo/office/word/MapMailMergeDataSource.java
+96
-0
MergeDataSource.java
...main/java/cn/datax/commo/office/word/MergeDataSource.java
+47
-0
WordUtil.java
src/main/java/cn/datax/commo/office/word/WordUtil.java
+0
-0
DataInner.java
...n/java/cn/datax/common/security/annotation/DataInner.java
+21
-0
No files found.
pom.xml
View file @
633c69bc
...
...
@@ -13,6 +13,7 @@
<maven.compiler.target>
8
</maven.compiler.target>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<mybatis-plus.version>
3.3.2
</mybatis-plus.version>
<aspose.version>
20.3
</aspose.version>
</properties>
<dependencies>
...
...
@@ -83,8 +84,13 @@
<groupId>
org.springframework.data
</groupId>
<artifactId>
spring-data-redis
</artifactId>
</dependency>
<dependency>
<groupId>
com.aspose
</groupId>
<artifactId>
aspose-words
</artifactId>
<version>
${aspose.version}
</version>
<classifier>
jdk17
</classifier>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
...
...
@@ -98,6 +104,11 @@
</dependencyManagement>
<repositories>
<repository>
<id>
AsposeJavaAPI
</id>
<name>
Aspose Java API
</name>
<url>
http://repository.aspose.com/repo/
</url>
</repository>
<repository>
<id>
maven-public
</id>
<name>
maven-public
</name>
<!-- <url>https://maven.aliyun.com/repository/public</url>-->
...
...
src/main/java/cn/datax/commo/office/word/MapMailMergeDataSource.java
0 → 100644
View file @
633c69bc
package
cn
.
datax
.
commo
.
office
.
word
;
import
com.aspose.words.IMailMergeDataSource
;
import
com.aspose.words.ref.Ref
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
public
class
MapMailMergeDataSource
implements
IMailMergeDataSource
{
private
List
<
Map
<
String
,
Object
>>
dataList
;
private
int
index
;
/**
* word模板中的«TableStart:tableName»«TableEnd:tableName»对应
*/
private
String
tableName
=
null
;
/**
* @param dataList 数据集
* @param tableName 与模板中的Name对应
*/
public
MapMailMergeDataSource
(
List
<
Map
<
String
,
Object
>>
dataList
,
String
tableName
)
{
this
.
dataList
=
dataList
;
this
.
tableName
=
tableName
;
index
=
-
1
;
}
/**
* @param data 单个数据集
* @param tableName 与模板中的Name对应
*/
public
MapMailMergeDataSource
(
Map
<
String
,
Object
>
data
,
String
tableName
)
{
if
(
this
.
dataList
==
null
)
{
this
.
dataList
=
new
ArrayList
<
Map
<
String
,
Object
>>();
this
.
dataList
.
add
(
data
);
}
this
.
tableName
=
tableName
;
index
=
-
1
;
}
/**
* 获取结果集总数
*
* @return
*/
private
int
getCount
()
{
return
this
.
dataList
.
size
();
}
@Override
public
IMailMergeDataSource
getChildDataSource
(
String
arg0
)
throws
Exception
{
return
null
;
}
@Override
public
String
getTableName
()
throws
Exception
{
return
this
.
tableName
;
}
/**
* 实现接口
* 获取当前index指向数据行的数据
* 将数据存入args数组中即可
*
* @return ***返回false则不绑定数据***
*/
@Override
public
boolean
getValue
(
String
key
,
Ref
<
Object
>
args
)
throws
Exception
{
if
(
index
<
0
||
index
>=
this
.
getCount
())
{
return
false
;
}
if
(
args
!=
null
)
{
args
.
set
(
this
.
dataList
.
get
(
index
).
get
(
key
));
return
true
;
}
else
{
return
false
;
}
}
/**
* 实现接口
* 判断是否还有下一条记录
*/
@Override
public
boolean
moveNext
()
throws
Exception
{
index
+=
1
;
if
(
index
>=
this
.
getCount
())
{
return
false
;
}
return
true
;
}
}
src/main/java/cn/datax/commo/office/word/MergeDataSource.java
0 → 100644
View file @
633c69bc
package
cn
.
datax
.
commo
.
office
.
word
;
import
com.aspose.words.Document
;
import
com.aspose.words.MailMerge
;
import
java.util.List
;
import
java.util.Map
;
public
class
MergeDataSource
{
/**
* word模板普通数据填充
* @param name
* @param value
* @param modelPath
* @return
* @throws Exception
*/
public
Document
load
(
String
[]
name
,
Object
[]
value
,
String
modelPath
)
throws
Exception
{
Document
doc
=
new
Document
(
modelPath
);
// 这里可以做特殊字段处理(如:图片插入、字符对应的特殊符号[https://wenku.baidu.com/view/81b41244336c1eb91a375dcb.html])
// DocumentBuilder builder = new DocumentBuilder(doc);
// builder.moveToMergeField(key);
// builder.insertImage((BufferedImage) value);
MailMerge
merge
=
doc
.
getMailMerge
();
merge
.
execute
(
name
,
value
);
return
doc
;
}
/**
* word模板里有集合的表格填充
* @param name
* @param value
* @param modelPath
* @param dataList
* @return
* @throws Exception
*/
public
Document
load
(
String
[]
name
,
Object
[]
value
,
String
modelPath
,
List
<
Map
<
String
,
Object
>>
dataList
,
String
tableName
)
throws
Exception
{
Document
doc
=
new
Document
(
modelPath
);
MailMerge
merge
=
doc
.
getMailMerge
();
merge
.
execute
(
name
,
value
);
merge
.
executeWithRegions
(
new
MapMailMergeDataSource
(
dataList
,
tableName
));
return
doc
;
}
}
src/main/java/cn/datax/commo/office/word/WordUtil.java
0 → 100644
View file @
633c69bc
This diff is collapsed.
Click to expand it.
src/main/java/cn/datax/common/security/annotation/DataInner.java
0 → 100644
View file @
633c69bc
package
cn
.
datax
.
common
.
security
.
annotation
;
import
java.lang.annotation.*
;
/**
* 服务调用不鉴权注解
*
* @author yuwei
* @since 2019/10/30
*/
@Target
({
ElementType
.
PARAMETER
,
ElementType
.
METHOD
})
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Documented
public
@interface
DataInner
{
/**
* 是否AOP统一处理
*
* @return false, true
*/
boolean
value
()
default
true
;
}
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