Browse Source

修改cglib

image
Jiaju Zhuang 12 months ago
parent
commit
7929e366ae
  1. 45
      easyexcel-core/src/main/java/com/alibaba/excel/analysis/v07/XlsxSaxAnalyser.java
  2. 9
      easyexcel-core/src/main/java/com/alibaba/excel/enums/CellExtraTypeEnum.java
  3. 7
      easyexcel-core/src/main/java/com/alibaba/excel/read/listener/ModelBuildEventListener.java
  4. 4
      easyexcel-core/src/main/java/com/alibaba/excel/util/BeanMapUtils.java
  5. 2
      easyexcel-core/src/main/java/com/alibaba/excel/util/ClassUtils.java
  6. 3
      easyexcel-core/src/main/java/com/alibaba/excel/util/FieldUtils.java
  7. 4
      easyexcel-core/src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java
  8. 2
      easyexcel-support/pom.xml
  9. 7
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/Xls03Test.java
  10. 2
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/write/TempWriteTest.java
  11. 33
      pom.xml

45
easyexcel-core/src/main/java/com/alibaba/excel/analysis/v07/XlsxSaxAnalyser.java

@ -10,6 +10,7 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.regex.Pattern;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
@ -31,6 +32,7 @@ import com.alibaba.excel.util.SheetUtils;
import com.alibaba.excel.util.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackageAccess;
@ -79,6 +81,9 @@ public class XlsxSaxAnalyser implements ExcelReadExecutor {
*/
private final Map<Integer, CommentsTable> commentsTableMap;
private final Map<Integer, PackagePart> drawingMap;
private final Map<Integer, PackagePart> drawingResMap;
public XlsxSaxAnalyser(XlsxReadContext xlsxReadContext, InputStream decryptedStream) throws Exception {
this.xlsxReadContext = xlsxReadContext;
// Initialize cache
@ -106,6 +111,20 @@ public class XlsxSaxAnalyser implements ExcelReadExecutor {
sheetList = new ArrayList<>();
sheetMap = new HashMap<>();
commentsTableMap = new HashMap<>();
drawingMap = MapUtils.newHashMap();
drawingResMap = MapUtils.newHashMap();
// Reading images
if (xlsxReadContext.readWorkbookHolder().getExtraReadSet().contains(CellExtraTypeEnum.IMAGE)) {
List<PackagePart> drawingsPackagePartList = pkg.getPartsByName(
Pattern.compile("xl/drawings/drawing[0-9]+.xml"));
if (CollectionUtils.isNotEmpty(drawingsPackagePartList)) {
for (PackagePart drawingPackagePart : drawingsPackagePartList) {
log.info("xx{}", drawingPackagePart);
}
}
}
Map<Integer, PackageRelationshipCollection> packageRelationshipCollectionMap = MapUtils.newHashMap();
xlsxReadWorkbookHolder.setPackageRelationshipCollectionMap(packageRelationshipCollectionMap);
@ -121,7 +140,7 @@ public class XlsxSaxAnalyser implements ExcelReadExecutor {
if (xlsxReadContext.readWorkbookHolder().getExtraReadSet().contains(CellExtraTypeEnum.COMMENT)) {
Comments comments = ite.getSheetComments();
if (comments instanceof CommentsTable) {
commentsTableMap.put(index, (CommentsTable) comments);
commentsTableMap.put(index, (CommentsTable)comments);
}
}
if (xlsxReadContext.readWorkbookHolder().getExtraReadSet().contains(CellExtraTypeEnum.HYPERLINK)) {
@ -258,12 +277,36 @@ public class XlsxSaxAnalyser implements ExcelReadExecutor {
parseXmlSource(sheetMap.get(readSheet.getSheetNo()), new XlsxRowHandler(xlsxReadContext));
// Read comments
readComments(readSheet);
// Read image
readImages(readSheet);
// The last sheet is read
xlsxReadContext.analysisEventProcessor().endSheet(xlsxReadContext);
}
}
}
private void readImages(ReadSheet readSheet) {
if (!xlsxReadContext.readWorkbookHolder().getExtraReadSet().contains(CellExtraTypeEnum.IMAGE)) {
return;
}
//xlsxReadContext.xlsxReadWorkbookHolder().getOpcPackage().getPart();
//
//CommentsTable commentsTable = commentsTableMap.get(readSheet.getSheetNo());
//if (commentsTable == null) {
// return;
//}
//Iterator<CellAddress> cellAddresses = commentsTable.getCellAddresses();
//while (cellAddresses.hasNext()) {
// CellAddress cellAddress = cellAddresses.next();
// XSSFComment cellComment = commentsTable.findCellComment(cellAddress);
// CellExtra cellExtra = new CellExtra(CellExtraTypeEnum.COMMENT, cellComment.getString().toString(),
// cellAddress.getRow(), cellAddress.getColumn());
// xlsxReadContext.readSheetHolder().setCellExtra(cellExtra);
// xlsxReadContext.analysisEventProcessor().extra(xlsxReadContext);
//}
}
private void readComments(ReadSheet readSheet) {
if (!xlsxReadContext.readWorkbookHolder().getExtraReadSet().contains(CellExtraTypeEnum.COMMENT)) {
return;

9
easyexcel-core/src/main/java/com/alibaba/excel/enums/CellExtraTypeEnum.java

@ -17,5 +17,12 @@ public enum CellExtraTypeEnum {
/**
* Merge
*/
MERGE,;
MERGE,
/**
* Image
*/
IMAGE,
;
}

7
easyexcel-core/src/main/java/com/alibaba/excel/read/listener/ModelBuildEventListener.java

@ -4,9 +4,6 @@ import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Map;
import javax.print.DocFlavor.STRING;
import com.alibaba.excel.constant.EasyExcelConstants;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.enums.HeadKindEnum;
@ -17,15 +14,13 @@ import com.alibaba.excel.metadata.data.DataFormatData;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.read.metadata.holder.ReadSheetHolder;
import com.alibaba.excel.read.metadata.property.ExcelReadHeadProperty;
import com.alibaba.excel.support.cglib.beans.BeanMap;
import com.alibaba.excel.util.BeanMapUtils;
import com.alibaba.excel.util.BooleanUtils;
import com.alibaba.excel.util.ClassUtils;
import com.alibaba.excel.util.ConverterUtils;
import com.alibaba.excel.util.DateUtils;
import com.alibaba.excel.util.MapUtils;
import com.alibaba.excel.util.StringUtils;
import org.springframework.cglib.beans.BeanMap;
/**
* Convert to the object the user needs

4
easyexcel-core/src/main/java/com/alibaba/excel/util/BeanMapUtils.java

@ -1,7 +1,7 @@
package com.alibaba.excel.util;
import org.springframework.cglib.beans.BeanMap;
import org.springframework.cglib.core.DefaultNamingPolicy;
import com.alibaba.excel.support.cglib.beans.BeanMap;
import com.alibaba.excel.support.cglib.core.DefaultNamingPolicy;
/**
* bean utils

2
easyexcel-core/src/main/java/com/alibaba/excel/util/ClassUtils.java

@ -33,6 +33,7 @@ import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.alibaba.excel.metadata.property.FontProperty;
import com.alibaba.excel.metadata.property.NumberFormatProperty;
import com.alibaba.excel.metadata.property.StyleProperty;
import com.alibaba.excel.support.cglib.beans.BeanMap;
import com.alibaba.excel.write.metadata.holder.WriteHolder;
import lombok.AllArgsConstructor;
@ -41,7 +42,6 @@ import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.cglib.beans.BeanMap;
/**
* Licensed to the Apache Software Foundation (ASF) under one or more

3
easyexcel-core/src/main/java/com/alibaba/excel/util/FieldUtils.java

@ -5,8 +5,7 @@ import java.lang.reflect.Modifier;
import java.util.Map;
import com.alibaba.excel.metadata.NullObject;
import org.springframework.cglib.beans.BeanMap;
import com.alibaba.excel.support.cglib.beans.BeanMap;
/**
* Licensed to the Apache Software Foundation (ASF) under one or more

4
easyexcel-core/src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java

@ -1,12 +1,10 @@
package com.alibaba.excel.write.executor;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import com.alibaba.excel.context.WriteContext;
import com.alibaba.excel.enums.HeadKindEnum;
@ -14,6 +12,7 @@ import com.alibaba.excel.metadata.FieldCache;
import com.alibaba.excel.metadata.FieldWrapper;
import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.alibaba.excel.support.cglib.beans.BeanMap;
import com.alibaba.excel.util.BeanMapUtils;
import com.alibaba.excel.util.ClassUtils;
import com.alibaba.excel.util.FieldUtils;
@ -30,7 +29,6 @@ import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.springframework.cglib.beans.BeanMap;
/**
* Add the data into excel

2
easyexcel-support/pom.xml

@ -21,7 +21,7 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.3.27</version>
<version>5.3.31</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>

7
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/Xls03Test.java

@ -3,14 +3,13 @@ package com.alibaba.easyexcel.test.temp;
import java.util.List;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.support.cglib.beans.BeanMap;
import com.alibaba.excel.util.BeanMapUtils;
import com.alibaba.fastjson2.JSON;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cglib.beans.BeanMap;
import org.springframework.cglib.core.DebuggingClassWriter;
/**
* 临时测试
@ -32,8 +31,8 @@ public class Xls03Test {
@Test
public void test2() {
System.getProperties().put("sun.misc.ProxyGenerator.saveGeneratedFiles", "true");
System.setProperty(DebuggingClassWriter.DEBUG_LOCATION_PROPERTY,
"/Users/zhuangjiaju/IdeaProjects/easyexcel/target");
//System.setProperty(DebuggingClassWriter.DEBUG_LOCATION_PROPERTY,
// "/Users/zhuangjiaju/IdeaProjects/easyexcel/target");
CamlData camlData = new CamlData();
//camlData.setTest("test2");

2
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/write/TempWriteTest.java

@ -8,6 +8,7 @@ import java.util.Map;
import com.alibaba.easyexcel.test.demo.read.CustomStringStringConverter;
import com.alibaba.easyexcel.test.util.TestFileUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.support.cglib.beans.BeanMap;
import com.alibaba.excel.util.BeanMapUtils;
import com.alibaba.excel.util.FileUtils;
import com.alibaba.excel.util.ListUtils;
@ -24,7 +25,6 @@ import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.jupiter.api.Test;
import org.springframework.cglib.beans.BeanMap;
@Slf4j
public class TempWriteTest {

33
pom.xml

@ -87,10 +87,11 @@
<version>${revision}</version>
</dependency>
<!-- Using the latest version of support simultaneously requires global use of the shade plugin, which is prone to errors, so changing to support will be lower than the overall -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel-support</artifactId>
<version>${revision}</version>
<version>3.3.2</version>
</dependency>
<dependency>
@ -103,6 +104,11 @@
<artifactId>poi-ooxml</artifactId>
<version>5.2.3</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.32</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
@ -313,31 +319,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>${project.groupId}:${project.artifactId}</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>org.springframework</pattern>
<shadedPattern>com.alibaba.excel.support</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>

Loading…
Cancel
Save