Quellcode durchsuchen

整理一个测试通过版本

4.1.3.A
jueyue vor 7 Jahren
Ursprung
Commit
416c90ea8e
16 geänderte Dateien mit 66 neuen und 49 gelöschten Zeilen
  1. +1
    -1
      easypoi-annotation/pom.xml
  2. +1
    -1
      easypoi-annotation/src/main/java/cn/afterturn/easypoi/excel/annotation/Excel.java
  3. +1
    -1
      easypoi-base/pom.xml
  4. +0
    -5
      easypoi-base/src/main/java/cn/afterturn/easypoi/cache/manager/FileLoaderImpl.java
  5. +4
    -1
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/ImportParams.java
  6. +2
    -0
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/params/ExcelImportEntity.java
  7. +1
    -1
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/html/ExcelToHtmlService.java
  8. +1
    -1
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/CellValueService.java
  9. +9
    -6
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/ExcelImportService.java
  10. +4
    -4
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/base/ImportBaseService.java
  11. +1
    -1
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/sax/parse/SaxRowRead.java
  12. +36
    -11
      easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiElUtil.java
  13. +1
    -12
      easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiPublicUtil.java
  14. +1
    -1
      easypoi-web/pom.xml
  15. +2
    -2
      pom.xml
  16. +1
    -1
      文档/2. Excel 注解版/2.5 Map导入,自由发挥

+ 1
- 1
easypoi-annotation/pom.xml Datei anzeigen

@@ -4,7 +4,7 @@
<parent>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi</artifactId>
<version>3.1.0</version>
<version>3.1.1-SNAPSHOT</version>
</parent>
<artifactId>easypoi-annotation</artifactId>
<description>基础注解类,解耦合</description>

+ 1
- 1
easypoi-annotation/src/main/java/cn/afterturn/easypoi/excel/annotation/Excel.java Datei anzeigen

@@ -121,7 +121,7 @@ public @interface Excel {
* 导入路径,如果是图片可以填写,默认是upload/className/ IconEntity这个类对应的就是upload/Icon/
*
*/
public String savePath() default "upload";
public String savePath() default "/excel/upload/img";
/**
* 导出类型 1 是文本 2 是图片,3 是函数,10 是数字 默认是文本


+ 1
- 1
easypoi-base/pom.xml Datei anzeigen

@@ -4,7 +4,7 @@
<parent>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi</artifactId>
<version>3.1.0</version>
<version>3.1.1-SNAPSHOT</version>
</parent>
<artifactId>easypoi-base</artifactId>
<dependencies>


+ 0
- 5
easypoi-base/src/main/java/cn/afterturn/easypoi/cache/manager/FileLoaderImpl.java Datei anzeigen

@@ -55,11 +55,6 @@ public class FileLoaderImpl implements IFileLoader {
} catch (FileNotFoundException e) {
//获取项目文件
fileis = FileLoaderImpl.class.getClassLoader().getResourceAsStream(url);
if (fileis == null) {
//最后再拿相对文件路径
String path = PoiPublicUtil.getWebRootPath(url);
fileis = new FileInputStream(path);
}
}
}



+ 4
- 1
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/ImportParams.java Datei anzeigen

@@ -26,6 +26,9 @@ import cn.afterturn.easypoi.handler.inter.IExcelVerifyHandler;
*/
@SuppressWarnings("rawtypes")
public class ImportParams extends ExcelBaseParams {
public static final String SAVE_URL = "/excel/upload/excelUpload";
/**
* 表格标题行数,默认0
*/
@@ -73,7 +76,7 @@ public class ImportParams extends ExcelBaseParams {
* 保存上传的Excel目录,默认是 如 TestEntity这个类保存路径就是
* upload/excelUpload/Test/yyyyMMddHHmss_***** 保存名称上传时间_五位随机数
*/
private String saveUrl = "upload/excelUpload";
private String saveUrl = SAVE_URL;
/**
* 最后的无效行数
*/


+ 2
- 0
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/params/ExcelImportEntity.java Datei anzeigen

@@ -23,6 +23,8 @@ import java.util.List;
* @version 1.0 2013年8月24日
*/
public class ExcelImportEntity extends ExcelBaseEntity {
public final static String IMG_SAVE_PATH = "/excel/upload/img";
/**
* 对应 Collection NAME
*/


+ 1
- 1
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/html/ExcelToHtmlService.java Datei anzeigen

@@ -278,7 +278,7 @@ public class ExcelToHtmlService {
/*String fileName = "pic" + Math.round(Math.random() * 100000000000L);
fileName += "." + PoiPublicUtil.getFileExtendName(data);
if (!imageCachePath.startsWith("/") && !imageCachePath.contains(":")) {
imageCachePath = PoiPublicUtil.getWebRootPath(imageCachePath);
imageCachePath = FileUtilTest.getWebRootPath(imageCachePath);
}
File savefile = new File(imageCachePath + "/" + today);
if (!savefile.exists()) {


+ 1
- 1
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/CellValueService.java Datei anzeigen

@@ -309,7 +309,7 @@ public class CellValueService {
}
return String.valueOf(result);
}
if (clazz.isEnum()) {
if (clazz != null && clazz.isEnum()) {
if (StringUtils.isNotEmpty(entity.getEnumImportMethod())) {
return PoiReflectorUtil.fromCache(clazz).execEnumStaticMethod(entity.getEnumImportMethod(),result);
} else {


+ 9
- 6
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/ExcelImportService.java Datei anzeigen

@@ -145,14 +145,14 @@ public class ExcelImportService extends ImportBaseService {
*/
private String getSaveUrl(ExcelImportEntity excelImportEntity, Object object) throws Exception {
String url = "";
if ("upload".equals(excelImportEntity.getSaveUrl())) {
if (ExcelImportEntity.IMG_SAVE_PATH.equals(excelImportEntity.getSaveUrl())) {
if (excelImportEntity.getMethods() != null
&& excelImportEntity.getMethods().size() > 0) {
object = getFieldBySomeMethod(excelImportEntity.getMethods(), object);
}
url = object.getClass().getName()
.split("\\.")[object.getClass().getName().split("\\.").length - 1];
return excelImportEntity.getSaveUrl() + "/" + url;
return excelImportEntity.getSaveUrl() + File.separator + url;
}
return excelImportEntity.getSaveUrl();
}
@@ -186,6 +186,10 @@ public class ExcelImportService extends ImportBaseService {
for (int i = 0; i < params.getStartRows(); i++) {
rows.next();
}
//判断index 和集合,集合情况默认为第一列
if (excelCollection.size() > 0 && params.getKeyIndex() == null) {
params.setKeyIndex(0);
}
while (rows.hasNext()
&& (row == null
|| sheet.getLastRowNum() - row.getRowNum() > params.getLastOfInvalidRow())) {
@@ -585,13 +589,12 @@ public class ExcelImportService extends ImportBaseService {
String fileName = "pic" + Math.round(Math.random() * 100000000000L);
fileName += "." + PoiPublicUtil.getFileExtendName(data);
if (excelParams.get(titleString).getSaveType() == 1) {
String path = PoiPublicUtil
.getWebRootPath(getSaveUrl(excelParams.get(titleString), object));
String path = getSaveUrl(excelParams.get(titleString), object);
File savefile = new File(path);
if (!savefile.exists()) {
savefile.mkdirs();
}
savefile = new File(path + "/" + fileName);
savefile = new File(path + File.separator + fileName);
FileOutputStream fos = new FileOutputStream(savefile);
try {
fos.write(data);
@@ -599,7 +602,7 @@ public class ExcelImportService extends ImportBaseService {
IOUtils.closeQuietly(fos);
}
setValues(excelParams.get(titleString), object,
getSaveUrl(excelParams.get(titleString), object) + "/" + fileName);
getSaveUrl(excelParams.get(titleString), object) + File.separator + fileName);
} else {
setValues(excelParams.get(titleString), object, data);
}


+ 4
- 4
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/base/ImportBaseService.java Datei anzeigen

@@ -214,14 +214,14 @@ public class ImportBaseService {
public void saveThisExcel(ImportParams params, Class<?> pojoClass, boolean isXSSFWorkbook,
Workbook book) throws Exception {
String path = PoiPublicUtil.getWebRootPath(getSaveExcelUrl(params, pojoClass));
String path = getSaveExcelUrl(params, pojoClass);
File savefile = new File(path);
if (!savefile.exists()) {
savefile.mkdirs();
}
SimpleDateFormat format = new SimpleDateFormat("yyyMMddHHmmss");
FileOutputStream fos = new FileOutputStream(
path + "/" + format.format(new Date()) + "_" + Math.round(Math.random() * 100000)
path + File.separator + format.format(new Date()) + "_" + Math.round(Math.random() * 100000)
+ (isXSSFWorkbook == true ? ".xlsx" : ".xls"));
book.write(fos);
IOUtils.closeQuietly(fos);
@@ -237,9 +237,9 @@ public class ImportBaseService {
*/
public String getSaveExcelUrl(ImportParams params, Class<?> pojoClass) throws Exception {
String url = "";
if ("upload/excelUpload".equals(params.getSaveUrl())) {
if (ImportParams.SAVE_URL.equals(params.getSaveUrl())) {
url = pojoClass.getName().split("\\.")[pojoClass.getName().split("\\.").length - 1];
return params.getSaveUrl() + "/" + url;
return params.getSaveUrl() + File.separator + url;
}
return params.getSaveUrl();
}


+ 1
- 1
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/sax/parse/SaxRowRead.java Datei anzeigen

@@ -129,7 +129,7 @@ public class SaxRowRead extends ImportBaseService implements ISaxRowRead {
*/
private void addListData(List<SaxReadCellEntity> datas) throws Exception {
// 判断是集合元素还是不是集合元素,如果是就继续加入这个集合,不是就创建新的对象
if ((datas.get(params.getKeyIndex()) == null
if (params.getKeyIndex() != null && (datas.get(params.getKeyIndex()) == null
|| StringUtils.isEmpty(String.valueOf(datas.get(params.getKeyIndex()).getValue())))
&& object != null) {
for (ExcelCollectionParams param : excelCollection) {


+ 36
- 11
easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiElUtil.java Datei anzeigen

@@ -59,9 +59,34 @@ public final class PoiElUtil {
public static Object eval(String text, Map<String, Object> map) throws Exception {
String tempText = new String(text);
Object obj = innerEval(text, map);
//如果没有被处理而且这个值找map中存在就处理这个值
if (tempText.equals(obj.toString()) && map.containsKey(tempText.split("\\.")[0])) {
return PoiPublicUtil.getParamsValue(tempText, map);
//如果没有被处理而且这个值找map中存在就处理这个值,找不到就返回空字符串
if (tempText.equals(obj.toString())) {
if(map.containsKey(tempText.split("\\.")[0])){
return PoiPublicUtil.getParamsValue(tempText, map);
}else{
return "";
}
}
return obj;
}
/**
* 解析字符串,支持 le,fd,fn,!if,三目 找不到返回原值
* @param text
* @param map
* @return
* @throws Exception
*/
public static Object evalNoParse(String text, Map<String, Object> map) throws Exception {
String tempText = new String(text);
Object obj = innerEval(text, map);
//如果没有被处理而且这个值找map中存在就处理这个值,找不到就返回空字符串
if (tempText.equals(obj.toString())) {
if(map.containsKey(tempText.split("\\.")[0])){
return PoiPublicUtil.getParamsValue(tempText, map);
}else{
return obj;
}
}
return obj;
}
@@ -126,8 +151,8 @@ public final class PoiElUtil {
return Boolean.valueOf(PoiPublicUtil.getParamsValue(keys[0], map).toString());
}
if (keys.length == 3) {
Object first = eval(keys[0], map);
Object second = eval(keys[2], map);
Object first = evalNoParse(keys[0], map);
Object second = evalNoParse(keys[2], map);
return PoiFunctionUtil.isTrue(first, keys[1], second);
}
throw new ExcelExportException("判断参数不对");
@@ -242,19 +267,19 @@ public final class PoiElUtil {
for (int i = 1; i < keys.length-1; i++) {
trinocular += ":" + keys[i];
}
first = eval(trinocular, map);
second = eval(keys[keys.length-1].trim(), map);
first = evalNoParse(trinocular, map);
second = evalNoParse(keys[keys.length-1].trim(), map);
} else {
first = eval(keys[0].trim(), map);
first = evalNoParse(keys[0].trim(), map);
String trinocular = keys[1];
for (int i = 2; i < keys.length; i++) {
trinocular += ":" + keys[i];
}
second = eval(trinocular, map);
second = evalNoParse(trinocular, map);
}
}else{
first = eval(keys[0].trim(), map);
second = eval(keys[1].trim(), map);
first = evalNoParse(keys[0].trim(), map);
second = evalNoParse(keys[1].trim(), map);
}
return isTrue(testText.split(" "), map) ? first : second;
}


+ 1
- 12
easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiPublicUtil.java Datei anzeigen

@@ -220,17 +220,6 @@ public final class PoiPublicUtil {
return sheetIndexPicMap;
}
public static String getWebRootPath(String filePath) {
try {
String path = PoiPublicUtil.class.getClassLoader().getResource("").toURI().getPath();
path = path.replace("WEB-INF/classes/", "");
path = path.replace("file:/", "");
return path + filePath;
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}
/**
* 判断是不是集合的实现类
*
@@ -460,7 +449,7 @@ public final class PoiPublicUtil {
* @param currentText
*/
public static void setWordText(XWPFRun currentRun, String currentText) {
if (StringUtils.isNotBlank(currentText)) {
if (StringUtils.isNotEmpty(currentText)) {
String[] tempArr = currentText.split("\r\n");
for (int i = 0, le = tempArr.length - 1; i < le; i++) {
currentRun.setText(tempArr[i], i);


+ 1
- 1
easypoi-web/pom.xml Datei anzeigen

@@ -4,7 +4,7 @@
<parent>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi</artifactId>
<version>3.1.0</version>
<version>3.1.1-SNAPSHOT</version>
</parent>
<artifactId>easypoi-web</artifactId>
<dependencies>


+ 2
- 2
pom.xml Datei anzeigen

@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi</artifactId>
<version>3.1.0</version>
<version>3.1.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>easypoi</name>
<modules>
@@ -45,7 +45,7 @@
</organization>
<properties>
<sub.version>3.1.0</sub.version>
<sub.version>3.1.1-SNAPSHOT</sub.version>
<poi.version>3.15</poi.version>
<xerces.version>2.9.1</xerces.version>
<guava.version>16.0.1</guava.version>


+ 1
- 1
文档/2. Excel 注解版/2.5 Map导入,自由发挥 Datei anzeigen

@@ -9,7 +9,7 @@
params.setDataHandler(new MapImportHandler());
long start = new Date().getTime();
List<Map<String, Object>> list = ExcelImportUtil.importExcel(
new File(PoiPublicUtil.getWebRootPath("import/check.xls")), Map.class, params);
new File(FileUtilTest.getWebRootPath("import/check.xls")), Map.class, params);
```
导入后,处理每个map,然后入库完美的解决了老师的需求,简单更快捷,和bean导入基础没有区别,省去了bean的构造时间



Laden…
Abbrechen
Speichern