remove 移除原生excel工具

master
疯狂的狮子li 5 years ago
parent 5ca4478540
commit ffed5a09cb

@ -1,165 +0,0 @@
package com.ruoyi.common.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.math.BigDecimal;
/**
* Excel
*
* @author ruoyi
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface Excel
{
/**
* excel
*/
public int sort() default Integer.MAX_VALUE;
/**
* Excel.
*/
public String name() default "";
/**
* , : yyyy-MM-dd
*/
public String dateFormat() default "";
/**
* type (: sys_user_sex)
*/
public String dictType() default "";
/**
* (: 0=,1=,2=)
*/
public String readConverterExp() default "";
/**
*
*/
public String separator() default ",";
/**
* BigDecimal :-1(BigDecimal)
*/
public int scale() default -1;
/**
* BigDecimal :BigDecimal.ROUND_HALF_EVEN
*/
public int roundingMode() default BigDecimal.ROUND_HALF_EVEN;
/**
* 0 1
*/
public ColumnType cellType() default ColumnType.STRING;
/**
* excel
*/
public double height() default 14;
/**
* excel
*/
public double width() default 16;
/**
* ,% 90 90%
*/
public String suffix() default "";
/**
* ,
*/
public String defaultValue() default "";
/**
*
*/
public String prompt() default "";
/**
* .
*/
public String[] combo() default {};
/**
* ,:,.
*/
public boolean isExport() default true;
/**
* ,,
*/
public String targetAttr() default "";
/**
* ,
*/
public boolean isStatistics() default false;
/**
* 0123
*/
Align align() default Align.AUTO;
public enum Align
{
AUTO(0), LEFT(1), CENTER(2), RIGHT(3);
private final int value;
Align(int value)
{
this.value = value;
}
public int value()
{
return this.value;
}
}
/**
* 012
*/
Type type() default Type.ALL;
public enum Type
{
ALL(0), EXPORT(1), IMPORT(2);
private final int value;
Type(int value)
{
this.value = value;
}
public int value()
{
return this.value;
}
}
public enum ColumnType
{
NUMERIC(0), STRING(1), IMAGE(2);
private final int value;
ColumnType(int value)
{
this.value = value;
}
public int value()
{
return this.value;
}
}
}

@ -1,18 +0,0 @@
package com.ruoyi.common.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Excel
*
* @author ruoyi
*/
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Excels
{
Excel[] value();
}

@ -1,150 +0,0 @@
package com.ruoyi.common.utils.poi;
import cn.hutool.core.util.IdUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
import com.ruoyi.common.utils.DictUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.file.FileUtils;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.List;
/**
* Excel
*
* @author ruoyi
*/
public class ExcelUtils {
/**
* excellistEasyExcel
*
* @param is
* @return
*/
public static <T> List<T> importExcel(InputStream is, Class<T> clazz) {
return EasyExcel.read(is).autoCloseStream(false).sheet().doReadSync();
}
/**
* listexcelEasyExcel
*
* @param list
* @param sheetName
* @return
*/
public static <T> void exportExcel(List<T> list, String sheetName, Class<T> clazz, HttpServletResponse response) {
try {
String filename = encodingFilename(sheetName);
response.reset();
response.addHeader("Access-Control-Allow-Origin", "*");
response.addHeader("Access-Control-Expose-Headers", "Content-Disposition");
FileUtils.setAttachmentResponseHeader(response, URLEncoder.encode(filename, StandardCharsets.UTF_8.toString()));
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8");
ServletOutputStream os = response.getOutputStream();
EasyExcel.write(os, clazz)
.autoCloseStream(false)
// 自动适配
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
.sheet(sheetName).doWrite(list);
} catch (IOException e) {
throw new RuntimeException("导出Excel异常");
}
}
/**
* 0=,1=,2=
*
* @param propertyValue
* @param converterExp
* @param separator
* @return
*/
public static String convertByExp(String propertyValue, String converterExp, String separator) {
StringBuilder propertyString = new StringBuilder();
String[] convertSource = converterExp.split(",");
for (String item : convertSource) {
String[] itemArray = item.split("=");
if (StringUtils.containsAny(separator, propertyValue)) {
for (String value : propertyValue.split(separator)) {
if (itemArray[0].equals(value)) {
propertyString.append(itemArray[1] + separator);
break;
}
}
} else {
if (itemArray[0].equals(propertyValue)) {
return itemArray[1];
}
}
}
return StringUtils.stripEnd(propertyString.toString(), separator);
}
/**
* =0,=1,=2
*
* @param propertyValue
* @param converterExp
* @param separator
* @return
*/
public static String reverseByExp(String propertyValue, String converterExp, String separator) {
StringBuilder propertyString = new StringBuilder();
String[] convertSource = converterExp.split(",");
for (String item : convertSource) {
String[] itemArray = item.split("=");
if (StringUtils.containsAny(separator, propertyValue)) {
for (String value : propertyValue.split(separator)) {
if (itemArray[1].equals(value)) {
propertyString.append(itemArray[0] + separator);
break;
}
}
} else {
if (itemArray[1].equals(propertyValue)) {
return itemArray[0];
}
}
}
return StringUtils.stripEnd(propertyString.toString(), separator);
}
/**
*
*
* @param dictValue
* @param dictType
* @param separator
* @return
*/
public static String convertDictByExp(String dictValue, String dictType, String separator) {
return DictUtils.getDictLabel(dictType, dictValue, separator);
}
/**
*
*
* @param dictLabel
* @param dictType
* @param separator
* @return
*/
public static String reverseDictByExp(String dictLabel, String dictType, String separator) {
return DictUtils.getDictValue(dictType, dictLabel, separator);
}
/**
*
*/
public static String encodingFilename(String filename) {
return IdUtil.fastSimpleUUID() + "_" + filename + ".xlsx";
}
}
Loading…
Cancel
Save