Initial commit
This commit is contained in:
35
tiesheng-poi/pom.xml
Normal file
35
tiesheng-poi/pom.xml
Normal file
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.tiesheng</groupId>
|
||||
<artifactId>tiesheng-parent</artifactId>
|
||||
<version>0.0.1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>tiesheng-poi</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>easyexcel</artifactId>
|
||||
<version>3.1.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng</groupId>
|
||||
<artifactId>tiesheng-util</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.tiesheng.poi.read;
|
||||
|
||||
import cn.hutool.core.util.ClassUtil;
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import com.alibaba.excel.read.listener.ReadListener;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class PoiReadBase {
|
||||
|
||||
|
||||
/**
|
||||
* 读取文件
|
||||
*
|
||||
* @param file
|
||||
* @param readListener
|
||||
* @return
|
||||
*/
|
||||
public static <T> String read(File file, ReadListener<T> readListener) {
|
||||
Class<?> aClass = ClassUtil.getTypeArgument(readListener.getClass(), 0);
|
||||
EasyExcel.read(file, aClass, readListener).autoTrim(true).headRowNumber(1).sheet().doRead();
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.tiesheng.poi.write;
|
||||
|
||||
import cn.hutool.core.util.ClassUtil;
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import com.alibaba.excel.annotation.write.style.*;
|
||||
import com.alibaba.excel.enums.poi.HorizontalAlignmentEnum;
|
||||
import com.alibaba.excel.enums.poi.VerticalAlignmentEnum;
|
||||
import com.alibaba.excel.support.ExcelTypeEnum;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author hao
|
||||
*/
|
||||
@HeadRowHeight(24)
|
||||
@HeadFontStyle(fontHeightInPoints = 13)
|
||||
@HeadStyle(horizontalAlignment = HorizontalAlignmentEnum.LEFT)
|
||||
@ContentRowHeight(20)
|
||||
@ContentFontStyle(fontHeightInPoints = 12)
|
||||
@ContentStyle(verticalAlignment = VerticalAlignmentEnum.CENTER)
|
||||
@ColumnWidth(20)
|
||||
public class PoiWriteBase {
|
||||
|
||||
|
||||
/**
|
||||
* 导出数据
|
||||
*
|
||||
* @param list
|
||||
* @return
|
||||
*/
|
||||
public static <T> boolean export(List<T> list, String absPath, String sheetName) {
|
||||
Class<?> aClass = ClassUtil.getTypeArgument(list.getClass(), 0);
|
||||
EasyExcel.write(absPath, aClass).excelType(ExcelTypeEnum.XLSX)
|
||||
.sheet(sheetName)
|
||||
.doWrite(list);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user