Initial commit
This commit is contained in:
@@ -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