Commit 633c69bc by hy

集成common-office模块

parent 36b0b886
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
<maven.compiler.target>8</maven.compiler.target> <maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<mybatis-plus.version>3.3.2</mybatis-plus.version> <mybatis-plus.version>3.3.2</mybatis-plus.version>
<aspose.version>20.3</aspose.version>
</properties> </properties>
<dependencies> <dependencies>
...@@ -83,8 +84,13 @@ ...@@ -83,8 +84,13 @@
<groupId>org.springframework.data</groupId> <groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId> <artifactId>spring-data-redis</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-words</artifactId>
<version>${aspose.version}</version>
<classifier>jdk17</classifier>
</dependency>
</dependencies> </dependencies>
<dependencyManagement> <dependencyManagement>
<dependencies> <dependencies>
<dependency> <dependency>
...@@ -98,6 +104,11 @@ ...@@ -98,6 +104,11 @@
</dependencyManagement> </dependencyManagement>
<repositories> <repositories>
<repository> <repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>http://repository.aspose.com/repo/</url>
</repository>
<repository>
<id>maven-public</id> <id>maven-public</id>
<name>maven-public</name> <name>maven-public</name>
<!-- <url>https://maven.aliyun.com/repository/public</url>--> <!-- <url>https://maven.aliyun.com/repository/public</url>-->
......
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;
}
}
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;
}
}
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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment