Browse Source

完成缓存逻辑

pull/507/head
zhuangjiaju 5 years ago
parent
commit
545c705c14
  1. 2
      src/main/java/com/alibaba/excel/analysis/v03/XlsSaxAnalyser.java
  2. 32
      src/main/java/com/alibaba/excel/analysis/v07/SharedStringsTableHandler.java
  3. 4
      src/main/java/com/alibaba/excel/analysis/v07/XlsxSaxAnalyser.java
  4. 4
      src/main/java/com/alibaba/excel/analysis/v07/handlers/ProcessResultCellHandler.java
  5. 206
      src/main/java/com/alibaba/excel/cache/Ehcache.java
  6. 123
      src/main/java/com/alibaba/excel/cache/EhcacheFile.java
  7. 123
      src/main/java/com/alibaba/excel/cache/EhcacheMix.java
  8. 19
      src/main/java/com/alibaba/excel/cache/MapCache.java
  9. 10
      src/main/java/com/alibaba/excel/cache/ReadCache.java
  10. 31
      src/main/java/com/alibaba/excel/cache/SharedStringsTableReadCache.java
  11. 7
      src/main/java/com/alibaba/excel/context/AnalysisContext.java
  12. 4
      src/main/java/com/alibaba/excel/context/AnalysisContextImpl.java
  13. 8
      src/main/java/com/alibaba/excel/context/WriteContext.java
  14. 8
      src/main/java/com/alibaba/excel/context/WriteContextImpl.java
  15. 494
      src/main/java/com/alibaba/excel/metadata/holder/read/AbstractWriteConfiguration.java
  16. 2
      src/main/java/com/alibaba/excel/metadata/holder/read/ReadConfiguration.java
  17. 235
      src/main/java/com/alibaba/excel/metadata/holder/read/SheetHolder.java
  18. 138
      src/main/java/com/alibaba/excel/metadata/holder/read/TableHolder.java
  19. 325
      src/main/java/com/alibaba/excel/metadata/holder/read/WorkbookHolder.java
  20. 5
      src/main/java/com/alibaba/excel/metadata/holder/write/AbstractWriteConfiguration.java
  21. 2
      src/main/java/com/alibaba/excel/metadata/holder/write/SheetHolder.java
  22. 2
      src/main/java/com/alibaba/excel/metadata/holder/write/TableHolder.java
  23. 2
      src/main/java/com/alibaba/excel/metadata/holder/write/WorkbookHolder.java
  24. 2
      src/main/java/com/alibaba/excel/metadata/holder/write/WriteConfiguration.java
  25. 2
      src/main/java/com/alibaba/excel/metadata/property/ExcelHeadProperty.java
  26. 2
      src/main/java/com/alibaba/excel/read/listener/ModelBuildEventListener.java
  27. 2
      src/main/java/com/alibaba/excel/read/listener/ReadListenerRegistryCenter.java
  28. 2
      src/main/java/com/alibaba/excel/read/listener/event/AnalysisFinishEvent.java
  29. 2
      src/main/java/com/alibaba/excel/read/listener/event/EachRowAnalysisFinishEvent.java
  30. 2
      src/main/java/com/alibaba/excel/util/WorkBookUtil.java
  31. 2
      src/main/java/com/alibaba/excel/write/ExcelBuilderImpl.java
  32. 4
      src/main/java/com/alibaba/excel/write/handler/CellWriteHandler.java
  33. 4
      src/main/java/com/alibaba/excel/write/handler/RowWriteHandler.java
  34. 4
      src/main/java/com/alibaba/excel/write/handler/SheetWriteHandler.java
  35. 2
      src/main/java/com/alibaba/excel/write/handler/WorkbookWriteHandler.java
  36. 4
      src/main/java/com/alibaba/excel/write/merge/AbstractMergeStrategy.java
  37. 6
      src/main/java/com/alibaba/excel/write/style/AbstractCellStyleStrategy.java
  38. 4
      src/main/java/com/alibaba/excel/write/style/column/AbstractColumnWidthStyleStrategy.java
  39. 4
      src/main/java/com/alibaba/excel/write/style/row/AbstractRowHeightStyleStrategy.java

2
src/main/java/com/alibaba/excel/analysis/v03/XlsSaxAnalyser.java

@ -27,7 +27,7 @@ import com.alibaba.excel.analysis.v03.handlers.NumberRecordHandler;
import com.alibaba.excel.analysis.v03.handlers.RKRecordHandler;
import com.alibaba.excel.analysis.v03.handlers.SSTRecordHandler;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.EachRowAnalysisFinishEvent;
import com.alibaba.excel.read.listener.event.EachRowAnalysisFinishEvent;
import com.alibaba.excel.exception.ExcelAnalysisException;
import com.alibaba.excel.metadata.Sheet;
import com.alibaba.excel.util.CollectionUtils;

32
src/main/java/com/alibaba/excel/analysis/v07/SharedStringsTableHandler.java

@ -1,9 +1,5 @@
package com.alibaba.excel.analysis.v07;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import com.alibaba.excel.cache.ReadCache;
@ -14,11 +10,9 @@ import com.alibaba.excel.cache.ReadCache;
* @author zhuangjiaju
*/
public class SharedStringsTableHandler extends DefaultHandler {
private static final Logger LOGGER = LoggerFactory.getLogger(SharedStringsTableHandler.class);
private static final String T_TAG = "t";
private String currentData;
private boolean isT;
private int index = 0;
private ReadCache readCache;
public SharedStringsTableHandler(ReadCache readCache) {
@ -26,28 +20,14 @@ public class SharedStringsTableHandler extends DefaultHandler {
}
@Override
public void startElement(String uri, String localName, String name, Attributes attributes) throws SAXException {
if ("t".equals(name)) {
currentData = null;
isT = true;
public void endElement(String uri, String localName, String name) {
if (T_TAG.equals(name)) {
readCache.put(currentData);
}
}
@Override
public void endElement(String uri, String localName, String name) throws SAXException {
if ("t".equals(name)) {
currentData = null;
isT = false;
}
}
@Override
public void characters(char[] ch, int start, int length) throws SAXException {
if (isT) {
readCache.put(index++, new String(ch, start, length));
if (index % 100000 == 0) {
LOGGER.info("row:{} ,mem:{},data:{}", index, Runtime.getRuntime().totalMemory());
}
}
public void characters(char[] ch, int start, int length) {
currentData = new String(ch, start, length);
}
}

4
src/main/java/com/alibaba/excel/analysis/v07/XlsxSaxAnalyser.java

@ -27,7 +27,7 @@ import com.alibaba.excel.cache.Ehcache;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.exception.ExcelAnalysisException;
import com.alibaba.excel.metadata.Sheet;
import com.alibaba.excel.metadata.holder.WorkbookHolder;
import com.alibaba.excel.metadata.holder.write.WorkbookHolder;
import com.alibaba.excel.util.FileUtils;
/**
@ -46,6 +46,8 @@ public class XlsxSaxAnalyser implements ExcelExecutor {
if (workbookHolder.getReadCache() == null) {
workbookHolder.setReadCache(new Ehcache());
}
workbookHolder.getReadCache().init(analysisContext);
OPCPackage pkg = readOpcPackage(workbookHolder);
// Analysis sharedStringsTable.xml

4
src/main/java/com/alibaba/excel/analysis/v07/handlers/ProcessResultCellHandler.java

@ -7,7 +7,7 @@ import org.xml.sax.Attributes;
import com.alibaba.excel.analysis.v07.XlsxCellHandler;
import com.alibaba.excel.analysis.v07.XlsxRowResultHolder;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.EachRowAnalysisFinishEvent;
import com.alibaba.excel.read.listener.event.EachRowAnalysisFinishEvent;
public class ProcessResultCellHandler implements XlsxCellHandler {
private AnalysisContext analysisContext;
@ -28,7 +28,7 @@ public class ProcessResultCellHandler implements XlsxCellHandler {
@Override
public void endHandle(String name) {
analysisContext.currentSheetHolder().notifyAll(
analysisContext.currentSheetHolder().notifyEndOneRow(
new EachRowAnalysisFinishEvent(rowResultHandler.getCurRowContent(), rowResultHandler.getColumnSize()),
analysisContext);
rowResultHandler.clearResult();

206
src/main/java/com/alibaba/excel/cache/Ehcache.java vendored

@ -4,10 +4,12 @@ import java.io.File;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.UUID;
import org.ehcache.CacheManager;
import org.ehcache.PersistentCacheManager;
import org.ehcache.config.builders.CacheConfigurationBuilder;
import org.ehcache.config.builders.CacheManagerBuilder;
@ -16,7 +18,8 @@ import org.ehcache.config.units.MemoryUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.excel.util.POITempFile;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.util.FileUtils;
import com.alibaba.excel.util.StringUtils;
/**
@ -25,99 +28,168 @@ import com.alibaba.excel.util.StringUtils;
* @author zhuangjiaju
*/
public class Ehcache implements ReadCache {
private static final Logger LOGGER = LoggerFactory.getLogger(Ehcache.class);
private static final int BATCH = 500;
// private org.ehcache.ReadCache<Integer, String> cache;
int index = 0;
int expirekey = 0;
private Map<Integer, String> cache = new HashMap<Integer, String>();
private static final int BATCH_COUNT = 500;
private static final int CHECK_INTERVAL = 1000;
private static final int MAX_CACHE_ACTIVATE = 10;
private static final String CACHE = "cache";
private static final String DATA_SEPARATOR = "@";
private static final String KEY_VALUE_SEPARATOR = "!";
private static final String SPECIAL_SEPARATOR = "&";
private static final String ESCAPED_DATA_SEPARATOR = "&d;";
private static final String ESCAPED_KEY_VALUE_SEPARATOR = "&kv;";
private static final String ESCAPED_SPECIAL_SEPARATOR = "&s;";
private int index = 0;
private StringBuilder data = new StringBuilder();
private CacheManager cacheManager;
/**
* Bulk storage data
*/
private org.ehcache.Cache<Integer, String> cache;
/**
* Currently active cache
*/
private Map<Integer, Map<Integer, String>> cacheMap = new HashMap<Integer, Map<Integer, String>>();
private TreeMap<Integer, Integer> expire = new TreeMap<Integer, Integer>();
private StringBuilder sb = new StringBuilder();
private Set<Integer> count = new HashSet<Integer>();
private int getCount = 1;
/**
* Count how many times get
*/
private int getCount = 0;
/**
* Count active cache
*
*/
private LinkedList<Integer> countList = new LinkedList<Integer>();
/**
* Count the last {@link #CHECK_INTERVAL} used
*/
private Set<Integer> lastCheckIntervalUsedSet = new HashSet<Integer>();
/**
* Count the number of cache misses
*/
private int cacheMiss = 0;
public Ehcache() {
File file = POITempFile.createCacheTmpFile();
@Override
public void init(AnalysisContext analysisContext) {
File readTempFile = analysisContext.currentWorkbookHolder().getReadTempFile();
if (readTempFile == null) {
readTempFile = FileUtils.createCacheTmpFile();
analysisContext.currentWorkbookHolder().setReadTempFile(readTempFile);
}
File cacheFile = new File(readTempFile.getPath(), UUID.randomUUID().toString());
PersistentCacheManager persistentCacheManager =
CacheManagerBuilder.newCacheManagerBuilder().with(CacheManagerBuilder.persistence(file))
.withCache("cache", CacheConfigurationBuilder.newCacheConfigurationBuilder(Integer.class, String.class,
CacheManagerBuilder.newCacheManagerBuilder().with(CacheManagerBuilder.persistence(cacheFile))
.withCache(CACHE, CacheConfigurationBuilder.newCacheConfigurationBuilder(Integer.class, String.class,
ResourcePoolsBuilder.newResourcePoolsBuilder().disk(10, MemoryUnit.GB)))
.build(true);
// this.cache = persistentCacheManager.getCache("cache", Integer.class, String.class);
cacheManager = persistentCacheManager;
cache = persistentCacheManager.getCache(CACHE, Integer.class, String.class);
}
@Override
public void put(Integer key, String value) {
sb.append(index++).append(":").append(value).append(",");
if (index != 0 && index % BATCH == 0) {
int key1 = index / BATCH;
cache.put(key1, sb.toString());
// LOGGER.info("put:key:{},{}", key1, sb.toString());
sb = new StringBuilder();
public void put(String value) {
data.append(index).append(KEY_VALUE_SEPARATOR).append(escape(value)).append(DATA_SEPARATOR);
if ((index + 1) % BATCH_COUNT == 0) {
cache.put(index / BATCH_COUNT, data.toString());
data = new StringBuilder();
}
index++;
}
private String escape(String str) {
if (StringUtils.isEmpty(str)) {
return str;
}
str = str.replaceAll(SPECIAL_SEPARATOR, ESCAPED_SPECIAL_SEPARATOR);
str = str.replaceAll(DATA_SEPARATOR, ESCAPED_DATA_SEPARATOR);
str = str.replaceAll(KEY_VALUE_SEPARATOR, ESCAPED_KEY_VALUE_SEPARATOR);
return str;
}
private String unescape(String str) {
if (StringUtils.isEmpty(str)) {
return str;
}
str = str.replaceAll(ESCAPED_KEY_VALUE_SEPARATOR, KEY_VALUE_SEPARATOR);
str = str.replaceAll(ESCAPED_DATA_SEPARATOR, DATA_SEPARATOR);
str = str.replaceAll(ESCAPED_SPECIAL_SEPARATOR, SPECIAL_SEPARATOR);
return str;
}
@Override
public String get(Integer key) {
int route = key / BATCH;
route++;
if (!cacheMap.containsKey(route)) {
// LOGGER.info("key:{},route:{},missing", key, route);
Map<Integer, String> map = new HashMap<Integer, String>(10000 / 3 * 4 + 1);
String s = cache.get(route);
String[] values = s.split(",");
for (String value : values) {
String[] vv = value.split(":");
map.put(Integer.valueOf(vv[0]), vv[1]);
}
cacheMap.put(route, map);
expire.put(expirekey++, route);
}
count.add(route);
if (getCount++ % 1000 == 0) {
if (key == null || key < 0) {
return null;
}
getCount++;
int route = key / BATCH_COUNT;
if (cacheMap.containsKey(route)) {
lastCheckIntervalUsedSet.add(route);
countList.add(route);
checkClear();
return cacheMap.get(route).get(key);
}
Map<Integer, String> tempCacheMap = new HashMap<Integer, String>(BATCH_COUNT / 3 * 4 + 1);
String batchData = cache.get(route);
String[] dataStrings = batchData.split(DATA_SEPARATOR);
for (String dataString : dataStrings) {
String[] keyValue = dataString.split(KEY_VALUE_SEPARATOR);
tempCacheMap.put(Integer.valueOf(keyValue[0]), unescape(keyValue[1]));
}
cacheMap.put(route, tempCacheMap);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Cache misses count:{}", cacheMiss++);
}
lastCheckIntervalUsedSet.add(route);
checkClear();
return tempCacheMap.get(key);
}
private void checkClear() {
if (countList.size() > MAX_CACHE_ACTIVATE) {
Integer route = countList.getFirst();
countList.removeFirst();
cacheMap.remove(route);
}
if (getCount++ % CHECK_INTERVAL != 0) {
return;
}
Iterator<Map.Entry<Integer, Map<Integer, String>>> iterator = cacheMap.entrySet().iterator();
// LOGGER.info("size:{}", cacheMap.size());
while (iterator.hasNext()) {
Map.Entry<Integer, Map<Integer, String>> entry = iterator.next();
if (!count.contains(entry.getKey())) {
// LOGGER.info("route:{},remove", entry.getKey());
if (lastCheckIntervalUsedSet.contains(entry.getKey())) {
continue;
}
// Last 'CHECK_INTERVAL' not use
iterator.remove();
Iterator<Map.Entry<Integer, Integer>> ex = expire.entrySet().iterator();
while (ex.hasNext()) {
Map.Entry<Integer, Integer> e = ex.next();
if (e.getValue().equals(entry.getKey())) {
ex.remove();
Iterator<Integer> countIterator = countList.iterator();
while (countIterator.hasNext()) {
Integer route = countIterator.next();
if (route.equals(entry.getKey())) {
countIterator.remove();
break;
}
}
}
}
count.clear();
}
if (expire.size() > 10) {
int value1=expire.firstEntry().getValue();
int key1=expire.firstEntry().getKey();
cacheMap.remove(value1);
expire.remove(key1);
}
return cacheMap.get(route).get(key);
lastCheckIntervalUsedSet.clear();
}
@Override
public void finish() {
if (StringUtils.isEmpty(sb.toString())) {
public void putFinished() {
if (StringUtils.isEmpty(data.toString())) {
return;
}
int key1 = index / BATCH;
if (index % BATCH != 0) {
key1++;
cache.put(index / BATCH_COUNT, data.toString());
}
cache.put(key1, sb.toString());
// LOGGER.info("put:key:{},{}", key1 + 1, sb.toString());
@Override
public void destroy() {
cacheManager.close();
}
}

123
src/main/java/com/alibaba/excel/cache/EhcacheFile.java vendored

@ -1,123 +0,0 @@
package com.alibaba.excel.cache;
import java.io.File;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import org.ehcache.PersistentCacheManager;
import org.ehcache.config.builders.CacheConfigurationBuilder;
import org.ehcache.config.builders.CacheManagerBuilder;
import org.ehcache.config.builders.ResourcePoolsBuilder;
import org.ehcache.config.units.MemoryUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.excel.util.POITempFile;
import com.alibaba.excel.util.StringUtils;
/**
* Default cache
*
* @author zhuangjiaju
*/
public class EhcacheFile implements ReadCache {
private static final Logger LOGGER = LoggerFactory.getLogger(EhcacheFile.class);
private static final int BATCH = 500;
int index = 0;
int expirekey = 0;
private org.ehcache.Cache<Integer, String> cache;
// private Map<Integer, String> cache = new HashMap<Integer, String>();
private Map<Integer, Map<Integer, String>> cacheMap = new HashMap<Integer, Map<Integer, String>>();
private TreeMap<Integer, Integer> expire = new TreeMap<Integer, Integer>();
private StringBuilder sb = new StringBuilder();
private Set<Integer> count = new HashSet<Integer>();
private int getCount = 1;
public EhcacheFile() {
File file = POITempFile.createCacheTmpFile();
PersistentCacheManager persistentCacheManager =
CacheManagerBuilder.newCacheManagerBuilder().with(CacheManagerBuilder.persistence(file))
.withCache("cache", CacheConfigurationBuilder.newCacheConfigurationBuilder(Integer.class, String.class,
ResourcePoolsBuilder.newResourcePoolsBuilder().disk(10, MemoryUnit.GB)))
.build(true);
this.cache = persistentCacheManager.getCache("cache", Integer.class, String.class);
}
@Override
public void put(Integer key, String value) {
sb.append(index++).append(":").append(value).append(",");
if (index != 0 && index % BATCH == 0) {
int key1 = index / BATCH;
cache.put(key1, sb.toString());
// LOGGER.info("put:key:{},{}", key1, sb.toString());
sb = new StringBuilder();
}
}
@Override
public String get(Integer key) {
int route = key / BATCH;
route++;
if (!cacheMap.containsKey(route)) {
// LOGGER.info("key:{},route:{},missing", key, route);
Map<Integer, String> map = new HashMap<Integer, String>(10000 / 3 * 4 + 1);
String s = cache.get(route);
String[] values = s.split(",");
for (String value : values) {
String[] vv = value.split(":");
map.put(Integer.valueOf(vv[0]), vv[1]);
}
cacheMap.put(route, map);
expire.put(expirekey++, route);
}
count.add(route);
if (getCount++ % 1000 == 0) {
Iterator<Map.Entry<Integer, Map<Integer, String>>> iterator = cacheMap.entrySet().iterator();
// LOGGER.info("size:{}", cacheMap.size());
while (iterator.hasNext()) {
Map.Entry<Integer, Map<Integer, String>> entry = iterator.next();
if (!count.contains(entry.getKey())) {
// LOGGER.info("route:{},remove", entry.getKey());
iterator.remove();
Iterator<Map.Entry<Integer, Integer>> ex = expire.entrySet().iterator();
while (ex.hasNext()) {
Map.Entry<Integer, Integer> e = ex.next();
if (e.getValue().equals(entry.getKey())) {
ex.remove();
break;
}
}
}
}
count.clear();
}
if (expire.size() > 10) {
int value1 = expire.firstEntry().getValue();
int key1 = expire.firstEntry().getKey();
cacheMap.remove(value1);
expire.remove(key1);
}
return cacheMap.get(route).get(key);
}
@Override
public void finish() {
if (StringUtils.isEmpty(sb.toString())) {
return;
}
int key1 = index / BATCH;
if (index % BATCH != 0) {
key1++;
}
cache.put(key1, sb.toString());
// LOGGER.info("put:key:{},{}", key1 + 1, sb.toString());
}
}

123
src/main/java/com/alibaba/excel/cache/EhcacheMix.java vendored

@ -1,123 +0,0 @@
package com.alibaba.excel.cache;
import java.io.File;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import org.ehcache.PersistentCacheManager;
import org.ehcache.config.builders.CacheConfigurationBuilder;
import org.ehcache.config.builders.CacheManagerBuilder;
import org.ehcache.config.builders.ResourcePoolsBuilder;
import org.ehcache.config.units.MemoryUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.excel.util.POITempFile;
import com.alibaba.excel.util.StringUtils;
/**
* Default cache
*
* @author zhuangjiaju
*/
public class EhcacheMix implements ReadCache {
private static final Logger LOGGER = LoggerFactory.getLogger(EhcacheMix.class);
private static final int BATCH = 500;
int index = 0;
int expirekey = 0;
private org.ehcache.Cache<Integer, String> cache;
private Map<Integer, Map<Integer, String>> cacheMap = new HashMap<Integer, Map<Integer, String>>();
private TreeMap<Integer, Integer> expire = new TreeMap<Integer, Integer>();
private StringBuilder sb = new StringBuilder();
private Set<Integer> count = new HashSet<Integer>();
private int getCount = 1;
private int countRead = 0;
public EhcacheMix() {
File file = POITempFile.createCacheTmpFile();
PersistentCacheManager persistentCacheManager = CacheManagerBuilder.newCacheManagerBuilder()
.with(CacheManagerBuilder.persistence(file))
.withCache("cache", CacheConfigurationBuilder.newCacheConfigurationBuilder(Integer.class, String.class,
ResourcePoolsBuilder.newResourcePoolsBuilder().heap(20, MemoryUnit.MB).disk(2, MemoryUnit.GB, false)))
.build(true);
this.cache = persistentCacheManager.getCache("cache", Integer.class, String.class);
}
@Override
public void put(Integer key, String value) {
sb.append(index++).append(":").append(value).append(",");
if (index != 0 && index % BATCH == 0) {
int key1 = index / BATCH;
cache.put(key1, sb.toString());
// LOGGER.info("put:key:{},{}", key1, sb.toString());
sb = new StringBuilder();
}
}
@Override
public String get(Integer key) {
int route = key / BATCH;
route++;
if (!cacheMap.containsKey(route)) {
Map<Integer, String> map = new HashMap<Integer, String>(10000 / 3 * 4 + 1);
String s = cache.get(route);
String[] values = s.split(",");
for (String value : values) {
String[] vv = value.split(":");
map.put(Integer.valueOf(vv[0]), vv[1]);
}
cacheMap.put(route, map);
expire.put(expirekey++, route);
}
count.add(route);
if (getCount++ % 1000 == 0) {
Iterator<Map.Entry<Integer, Map<Integer, String>>> iterator = cacheMap.entrySet().iterator();
// LOGGER.info("size:{}", cacheMap.size());
while (iterator.hasNext()) {
Map.Entry<Integer, Map<Integer, String>> entry = iterator.next();
if (!count.contains(entry.getKey())) {
// LOGGER.info("route:{},remove", entry.getKey());
iterator.remove();
Iterator<Map.Entry<Integer, Integer>> ex = expire.entrySet().iterator();
while (ex.hasNext()) {
Map.Entry<Integer, Integer> e = ex.next();
if (e.getValue().equals(entry.getKey())) {
ex.remove();
break;
}
}
}
}
count.clear();
}
if (expire.size() > 10) {
int value1 = expire.firstEntry().getValue();
int key1 = expire.firstEntry().getKey();
cacheMap.remove(value1);
expire.remove(key1);
}
return cacheMap.get(route).get(key);
}
@Override
public void finish() {
if (StringUtils.isEmpty(sb.toString())) {
return;
}
int key1 = index / BATCH;
if (index % BATCH != 0) {
key1++;
}
cache.put(key1, sb.toString());
// LOGGER.info("put:key:{},{}", key1 + 1, sb.toString());
}
}

19
src/main/java/com/alibaba/excel/cache/Ehcache2.java → src/main/java/com/alibaba/excel/cache/MapCache.java vendored

@ -3,6 +3,8 @@ package com.alibaba.excel.cache;
import java.util.HashMap;
import java.util.Map;
import com.alibaba.excel.context.AnalysisContext;
/**
*
* Putting temporary data directly into a map is a little more efficient but very memory intensive
@ -11,19 +13,28 @@ import java.util.Map;
*/
public class MapCache implements ReadCache {
private Map<Integer, String> cache = new HashMap<Integer, String>();
private int index = 0;
public MapCache() {}
@Override
public void init(AnalysisContext analysisContext) {}
@Override
public void put(Integer key, String value) {
cache.put(key, value);
public void put(String value) {
cache.put(index++, value);
}
@Override
public String get(Integer key) {
if (key == null || key < 0) {
return null;
}
return cache.get(key);
}
@Override
public void finish() {}
public void putFinished() {}
@Override
public void destroy() {}
}

10
src/main/java/com/alibaba/excel/cache/ReadCache.java vendored

@ -1,11 +1,21 @@
package com.alibaba.excel.cache;
import com.alibaba.excel.context.AnalysisContext;
/**
* Read cache
*
* @author zhuangjiaju
*/
public interface ReadCache {
/**
* Initialize cache
*
* @param analysisContext
*/
void init(AnalysisContext analysisContext);
/**
* Automatically generate the key and put it in the cache.Key start from 0
*

31
src/main/java/com/alibaba/excel/cache/SharedStringsTableReadCache.java vendored

@ -1,31 +0,0 @@
package com.alibaba.excel.cache;
import org.apache.poi.xssf.model.SharedStringsTable;
/**
* Default cache
*
* @author zhuangjiaju
*/
public class SharedStringsTableReadCache implements ReadCache {
private SharedStringsTable sharedStringsTable;
public SharedStringsTableReadCache(SharedStringsTable sharedStringsTable) {
this.sharedStringsTable = sharedStringsTable;
}
@Override
public void put(Integer key, String value) {
throw new UnsupportedOperationException("Can not put value");
}
@Override
public String get(Integer key) {
return sharedStringsTable.getItemAt(key).toString();
}
@Override
public void finish() {
}
}

7
src/main/java/com/alibaba/excel/context/AnalysisContext.java

@ -1,9 +1,8 @@
package com.alibaba.excel.context;
import com.alibaba.excel.event.EachRowAnalysisFinishEvent;
import com.alibaba.excel.metadata.holder.ReadConfiguration;
import com.alibaba.excel.metadata.holder.SheetHolder;
import com.alibaba.excel.metadata.holder.WorkbookHolder;
import com.alibaba.excel.metadata.holder.read.ReadConfiguration;
import com.alibaba.excel.metadata.holder.write.SheetHolder;
import com.alibaba.excel.metadata.holder.write.WorkbookHolder;
/**
*

4
src/main/java/com/alibaba/excel/context/AnalysisContextImpl.java

@ -3,8 +3,8 @@ package com.alibaba.excel.context;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.excel.metadata.holder.SheetHolder;
import com.alibaba.excel.metadata.holder.WorkbookHolder;
import com.alibaba.excel.metadata.holder.write.SheetHolder;
import com.alibaba.excel.metadata.holder.write.WorkbookHolder;
/**
*

8
src/main/java/com/alibaba/excel/context/WriteContext.java

@ -1,10 +1,10 @@
package com.alibaba.excel.context;
import com.alibaba.excel.metadata.Table;
import com.alibaba.excel.metadata.holder.WriteConfiguration;
import com.alibaba.excel.metadata.holder.SheetHolder;
import com.alibaba.excel.metadata.holder.TableHolder;
import com.alibaba.excel.metadata.holder.WorkbookHolder;
import com.alibaba.excel.metadata.holder.write.WriteConfiguration;
import com.alibaba.excel.metadata.holder.write.SheetHolder;
import com.alibaba.excel.metadata.holder.write.TableHolder;
import com.alibaba.excel.metadata.holder.write.WorkbookHolder;
/**
* Write context

8
src/main/java/com/alibaba/excel/context/WriteContextImpl.java

@ -14,10 +14,10 @@ import org.slf4j.LoggerFactory;
import com.alibaba.excel.exception.ExcelGenerateException;
import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.metadata.Table;
import com.alibaba.excel.metadata.holder.SheetHolder;
import com.alibaba.excel.metadata.holder.TableHolder;
import com.alibaba.excel.metadata.holder.WorkbookHolder;
import com.alibaba.excel.metadata.holder.WriteConfiguration;
import com.alibaba.excel.metadata.holder.write.SheetHolder;
import com.alibaba.excel.metadata.holder.write.TableHolder;
import com.alibaba.excel.metadata.holder.write.WorkbookHolder;
import com.alibaba.excel.metadata.holder.write.WriteConfiguration;
import com.alibaba.excel.metadata.property.ExcelHeadProperty;
import com.alibaba.excel.util.WorkBookUtil;
import com.alibaba.excel.write.handler.CellWriteHandler;

494
src/main/java/com/alibaba/excel/metadata/holder/read/AbstractWriteConfiguration.java

@ -0,0 +1,494 @@
package com.alibaba.excel.metadata.holder.read;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Sheet;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.converters.ConverterKey;
import com.alibaba.excel.enums.HeadKindEnum;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.event.NotRepeatExecutor;
import com.alibaba.excel.event.Order;
import com.alibaba.excel.exception.ExcelAnalysisException;
import com.alibaba.excel.exception.ExcelDataConvertException;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.CellStyle;
import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.metadata.holder.write.WriteConfiguration;
import com.alibaba.excel.metadata.property.CellStyleProperty;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.alibaba.excel.metadata.property.ExcelHeadProperty;
import com.alibaba.excel.metadata.property.RowHeightProperty;
import com.alibaba.excel.read.listener.ReadListener;
import com.alibaba.excel.read.listener.ReadListenerRegistryCenter;
import com.alibaba.excel.read.listener.event.AnalysisFinishEvent;
import com.alibaba.excel.util.StringUtils;
import com.alibaba.excel.write.handler.CellWriteHandler;
import com.alibaba.excel.write.handler.RowWriteHandler;
import com.alibaba.excel.write.handler.SheetWriteHandler;
import com.alibaba.excel.write.handler.WorkbookWriteHandler;
import com.alibaba.excel.write.handler.WriteHandler;
import com.alibaba.excel.write.style.AbstractColumnCellStyleStrategy;
import com.alibaba.excel.write.style.column.AbstractColumnWidthStyleStrategy;
import com.alibaba.excel.write.style.row.SimpleRowHeightStyleStrategy;
/**
* sheet holder
*
* @author zhuangjiaju
*/
public abstract class AbstractWriteConfiguration
implements WriteConfiguration, ReadConfiguration, ReadListenerRegistryCenter {
/**
* Need Head
*/
private Boolean needHead;
/**
* Write handler for workbook
*/
private Map<Class<? extends WriteHandler>, List<WriteHandler>> writeHandlerMap;
/**
* Read listener
*/
private List<ReadListener> readListenerList;
/**
* Converter for workbook
*/
private Map<ConverterKey, Converter> readConverterMap;
/**
* Converter for workbook
*/
private Map<Class, Converter> writeConverterMap;
/**
* Excel head property
*/
private ExcelHeadProperty excelHeadProperty;
/**
* Writes the head relative to the existing contents of the sheet. Indexes are zero-based.
*/
private Integer writeRelativeHeadRowIndex;
/**
* Record whether it's new or from cache
*/
private Boolean newInitialization;
/**
* Count the number of added heads when read sheet.
*
* <li>0 - This Sheet has no head ,since the first row are the data
* <li>1 - This Sheet has one row head , this is the default
* <li>2 - This Sheet has two row head ,since the third row is the data
*/
private Integer readHeadRowNumber;
/**
* You can only choose one of the {@link AbstractWriteConfiguration#head} and
* {@link AbstractWriteConfiguration#clazz}
*/
private List<List<String>> head;
/**
* You can only choose one of the {@link AbstractWriteConfiguration#head} and
* {@link AbstractWriteConfiguration#clazz}
*/
private Class clazz;
/**
* Automatic trim includes sheet name and content
*/
private Boolean autoTrim;
public Boolean getNeedHead() {
return needHead;
}
public void setNeedHead(Boolean needHead) {
this.needHead = needHead;
}
public Map<Class<? extends WriteHandler>, List<WriteHandler>> getWriteHandlerMap() {
return writeHandlerMap;
}
public void setWriteHandlerMap(Map<Class<? extends WriteHandler>, List<WriteHandler>> writeHandlerMap) {
this.writeHandlerMap = writeHandlerMap;
}
public ExcelHeadProperty getExcelHeadProperty() {
return excelHeadProperty;
}
public void setExcelHeadProperty(ExcelHeadProperty excelHeadProperty) {
this.excelHeadProperty = excelHeadProperty;
}
public Integer getWriteRelativeHeadRowIndex() {
return writeRelativeHeadRowIndex;
}
public void setWriteRelativeHeadRowIndex(Integer writeRelativeHeadRowIndex) {
this.writeRelativeHeadRowIndex = writeRelativeHeadRowIndex;
}
public Boolean getNewInitialization() {
return newInitialization;
}
public void setNewInitialization(Boolean newInitialization) {
this.newInitialization = newInitialization;
}
public List<List<String>> getHead() {
return head;
}
public void setHead(List<List<String>> head) {
this.head = head;
}
public Class getClazz() {
return clazz;
}
public void setClazz(Class clazz) {
this.clazz = clazz;
}
public Boolean getAutoTrim() {
return autoTrim;
}
public void setAutoTrim(Boolean autoTrim) {
this.autoTrim = autoTrim;
}
public List<ReadListener> getReadListenerList() {
return readListenerList;
}
public void setReadListenerList(List<ReadListener> readListenerList) {
this.readListenerList = readListenerList;
}
public Map<ConverterKey, Converter> getReadConverterMap() {
return readConverterMap;
}
public void setReadConverterMap(Map<ConverterKey, Converter> readConverterMap) {
this.readConverterMap = readConverterMap;
}
public Map<Class, Converter> getWriteConverterMap() {
return writeConverterMap;
}
public void setWriteConverterMap(Map<Class, Converter> writeConverterMap) {
this.writeConverterMap = writeConverterMap;
}
public Integer getReadHeadRowNumber() {
return readHeadRowNumber;
}
public void setReadHeadRowNumber(Integer readHeadRowNumber) {
this.readHeadRowNumber = readHeadRowNumber;
}
@Override
public void register(AnalysisEventListener listener) {
readListenerList.add(listener);
}
@Override
public void notifyEndOneRow(AnalysisFinishEvent event, AnalysisContext analysisContext) {
List<CellData> cellDataList = (List<CellData>)event.getAnalysisResult();
if (analysisContext.currentRowNum() > analysisContext.currentSheetHolder().getReadHeadRowNumber()) {
for (ReadListener readListener : readListenerList) {
try {
readListener.invoke(analysisContext.currentRowAnalysisResult(), analysisContext);
} catch (Exception e) {
for (ReadListener readListenerException : readListenerList) {
try {
readListenerException.onException(e, analysisContext);
} catch (Exception exception) {
throw new ExcelAnalysisException("Listen error!", exception);
}
}
}
}
}
// Now is header
if (analysisContext.currentRowNum().equals(analysisContext.currentSheetHolder().getReadHeadRowNumber())) {
buildHead(analysisContext, cellDataList);
}
}
@Override
public void notifyAfterAllAnalysed(AnalysisContext analysisContext) {
for (ReadListener readListener : readListenerList) {
readListener.doAfterAllAnalysed(analysisContext);
}
}
private void buildHead(AnalysisContext analysisContext, List<CellData> cellDataList) {
if (!HeadKindEnum.CLASS.equals(analysisContext.currentConfiguration().excelHeadProperty().getHeadKind())) {
return;
}
List<String> dataList = (List<String>)buildStringList(cellDataList, analysisContext.currentConfiguration());
ExcelHeadProperty excelHeadPropertyData = analysisContext.currentConfiguration().excelHeadProperty();
Map<Integer, Head> headMapData = excelHeadPropertyData.getHeadMap();
Map<Integer, ExcelContentProperty> contentPropertyMapData = excelHeadPropertyData.getContentPropertyMap();
Map<Integer, Head> tmpHeadMap = new HashMap<Integer, Head>(headMapData.size() * 4 / 3 + 1);
Map<Integer, ExcelContentProperty> tmpContentPropertyMap =
new HashMap<Integer, ExcelContentProperty>(contentPropertyMapData.size() * 4 / 3 + 1);
for (Map.Entry<Integer, Head> entry : headMapData.entrySet()) {
Head headData = entry.getValue();
if (headData.getForceIndex()) {
tmpHeadMap.put(entry.getKey(), headData);
tmpContentPropertyMap.put(entry.getKey(), contentPropertyMapData.get(entry.getKey()));
continue;
}
String headName = headData.getHeadNameList().get(0);
for (int i = 0; i < dataList.size(); i++) {
String headString = dataList.get(i);
if (StringUtils.isEmpty(headString)) {
continue;
}
if (analysisContext.currentSheetHolder().getAutoTrim()) {
headString = headString.trim();
}
if (headName.equals(headString)) {
headData.setColumnIndex(i);
tmpHeadMap.put(i, headData);
tmpContentPropertyMap.put(i, contentPropertyMapData.get(entry.getKey()));
break;
}
}
}
excelHeadPropertyData.setHeadMap(tmpHeadMap);
excelHeadPropertyData.setContentPropertyMap(tmpContentPropertyMap);
}
private Object buildStringList(List<CellData> data, ReadConfiguration readConfiguration) {
List<String> list = new ArrayList<String>();
for (CellData cellData : data) {
Converter converter = readConfiguration.readConverterMap()
.get(ConverterKey.buildConverterKey(String.class, cellData.getType()));
if (converter == null) {
throw new ExcelDataConvertException(
"Converter not found, convert " + cellData.getType() + " to String");
}
try {
list.add((String)(converter.convertToJavaData(cellData, null)));
} catch (Exception e) {
throw new ExcelDataConvertException("Convert data " + cellData + " to String error ", e);
}
}
return list;
}
protected Map<Class<? extends WriteHandler>, List<WriteHandler>> sortAndClearUpHandler(
List<WriteHandler> handlerList, Map<Class<? extends WriteHandler>, List<WriteHandler>> parentHandlerMap) {
// add
if (parentHandlerMap != null) {
for (List<WriteHandler> parentHandlerList : parentHandlerMap.values()) {
handlerList.addAll(parentHandlerList);
}
}
// sort
Map<Integer, List<WriteHandler>> orderExcelWriteHandlerMap = new TreeMap<Integer, List<WriteHandler>>();
for (WriteHandler handler : handlerList) {
int order = Integer.MIN_VALUE;
if (handler instanceof Order) {
order = ((Order)handler).order();
}
if (orderExcelWriteHandlerMap.containsKey(order)) {
orderExcelWriteHandlerMap.get(order).add(handler);
} else {
List<WriteHandler> tempHandlerList = new ArrayList<WriteHandler>();
tempHandlerList.add(handler);
orderExcelWriteHandlerMap.put(order, tempHandlerList);
}
}
// clean up
Set<String> alreadyExistedHandlerSet = new HashSet<String>();
List<WriteHandler> cleanUpHandlerList = new ArrayList<WriteHandler>();
for (Map.Entry<Integer, List<WriteHandler>> entry : orderExcelWriteHandlerMap.entrySet()) {
for (WriteHandler handler : entry.getValue()) {
if (handler instanceof NotRepeatExecutor) {
String uniqueValue = ((NotRepeatExecutor)handler).uniqueValue();
if (alreadyExistedHandlerSet.contains(uniqueValue)) {
continue;
}
alreadyExistedHandlerSet.add(uniqueValue);
}
cleanUpHandlerList.add(handler);
}
}
// classify
Map<Class<? extends WriteHandler>, List<WriteHandler>> result =
new HashMap<Class<? extends WriteHandler>, List<WriteHandler>>();
result.put(WriteHandler.class, new ArrayList<WriteHandler>());
result.put(WorkbookWriteHandler.class, new ArrayList<WriteHandler>());
result.put(SheetWriteHandler.class, new ArrayList<WriteHandler>());
result.put(RowWriteHandler.class, new ArrayList<WriteHandler>());
result.put(CellWriteHandler.class, new ArrayList<WriteHandler>());
for (WriteHandler writeHandler : cleanUpHandlerList) {
if (writeHandler instanceof CellWriteHandler) {
result.get(CellWriteHandler.class).add(writeHandler);
}
if (writeHandler instanceof RowWriteHandler) {
result.get(RowWriteHandler.class).add(writeHandler);
}
if (writeHandler instanceof SheetWriteHandler) {
result.get(SheetWriteHandler.class).add(writeHandler);
}
if (writeHandler instanceof SheetWriteHandler) {
result.get(SheetWriteHandler.class).add(writeHandler);
}
if (writeHandler instanceof WorkbookWriteHandler) {
result.get(WorkbookWriteHandler.class).add(writeHandler);
}
result.get(WriteHandler.class).add(writeHandler);
}
return result;
}
protected void initAnnotationConfig(List<WriteHandler> handlerList) {
if (!HeadKindEnum.CLASS.equals(getExcelHeadProperty().getHeadKind())) {
return;
}
Map<Integer, Head> headMap = getExcelHeadProperty().getHeadMap();
Map<Integer, ExcelContentProperty> contentPropertyMap = getExcelHeadProperty().getContentPropertyMap();
boolean hasCellStyle = false;
boolean hasColumnWidth = false;
for (Map.Entry<Integer, Head> entry : headMap.entrySet()) {
if (entry.getValue().getCellStyleProperty() != null) {
hasCellStyle = true;
}
if (entry.getValue().getColumnWidthProperty() != null) {
hasColumnWidth = true;
}
ExcelContentProperty excelContentProperty = contentPropertyMap.get(entry.getKey());
if (excelContentProperty.getCellStyleProperty() != null) {
hasCellStyle = true;
}
}
if (hasCellStyle) {
dealCellStyle(handlerList, contentPropertyMap);
}
if (hasColumnWidth) {
dealColumnWidth(handlerList);
}
dealRowHigh(handlerList, contentPropertyMap);
}
private void dealRowHigh(List<WriteHandler> handlerList, Map<Integer, ExcelContentProperty> contentPropertyMap) {
RowHeightProperty headRowHeightProperty = excelHeadProperty.getHeadRowHeightProperty();
RowHeightProperty contentRowHeightProperty = excelHeadProperty.getContentRowHeightProperty();
if (headRowHeightProperty == null && contentRowHeightProperty == null) {
return;
}
Short headRowHeight = null;
if (headRowHeightProperty != null) {
headRowHeight = headRowHeightProperty.getHeight();
}
Short contentRowHeight = null;
if (contentRowHeightProperty != null) {
contentRowHeight = contentRowHeightProperty.getHeight();
}
handlerList.add(new SimpleRowHeightStyleStrategy(headRowHeight, contentRowHeight));
}
private void dealColumnWidth(List<WriteHandler> handlerList) {
WriteHandler columnWidthStyleStrategy = new AbstractColumnWidthStyleStrategy() {
@Override
protected void setColumnWidth(Sheet sheet, Cell cell, Head head) {
if (head == null) {
return;
}
if (head.getColumnWidthProperty() != null) {
sheet.setColumnWidth(head.getColumnIndex(), head.getColumnWidthProperty().getWidth());
}
}
};
handlerList.add(columnWidthStyleStrategy);
}
private void dealCellStyle(List<WriteHandler> handlerList,
final Map<Integer, ExcelContentProperty> contentPropertyMap) {
WriteHandler columnCellStyleStrategy = new AbstractColumnCellStyleStrategy() {
@Override
protected CellStyle headCellStyle(Head head) {
if (head == null || head.getCellStyleProperty() == null) {
return null;
}
CellStyleProperty cellStyleProperty = head.getCellStyleProperty();
return new CellStyle(cellStyleProperty.getFontName(), cellStyleProperty.getFontHeightInPoints(),
cellStyleProperty.getBold(), cellStyleProperty.getIndexedColors());
}
@Override
protected CellStyle contentCellStyle(Head head) {
if (head == null) {
return null;
}
ExcelContentProperty excelContentProperty = contentPropertyMap.get(head.getColumnIndex());
if (excelContentProperty == null || excelContentProperty.getCellStyleProperty() == null) {
return null;
}
CellStyleProperty cellStyleProperty = excelContentProperty.getCellStyleProperty();
return new CellStyle(cellStyleProperty.getFontName(), cellStyleProperty.getFontHeightInPoints(),
cellStyleProperty.getBold(), cellStyleProperty.getIndexedColors());
}
};
handlerList.add(columnCellStyleStrategy);
}
@Override
public Map<Class<? extends WriteHandler>, List<WriteHandler>> writeHandlerMap() {
return getWriteHandlerMap();
}
@Override
public boolean needHead() {
return getNeedHead();
}
@Override
public int writeRelativeHeadRowIndex() {
return getWriteRelativeHeadRowIndex();
}
@Override
public ExcelHeadProperty excelHeadProperty() {
return getExcelHeadProperty();
}
@Override
public boolean isNew() {
return getNewInitialization();
}
@Override
public List<ReadListener> readListenerList() {
return getReadListenerList();
}
@Override
public Map<ConverterKey, Converter> readConverterMap() {
return getReadConverterMap();
}
@Override
public Map<Class, Converter> writeConverterMap() {
return getWriteConverterMap();
}
}

2
src/main/java/com/alibaba/excel/metadata/holder/ReadConfiguration.java → src/main/java/com/alibaba/excel/metadata/holder/read/ReadConfiguration.java

@ -1,4 +1,4 @@
package com.alibaba.excel.metadata.holder;
package com.alibaba.excel.metadata.holder.read;
import java.util.List;
import java.util.Map;

235
src/main/java/com/alibaba/excel/metadata/holder/read/SheetHolder.java

@ -0,0 +1,235 @@
package com.alibaba.excel.metadata.holder.read;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.poi.ss.usermodel.Sheet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.converters.ConverterKey;
import com.alibaba.excel.metadata.CellStyle;
import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.metadata.TableStyle;
import com.alibaba.excel.metadata.holder.write.AbstractWriteConfiguration;
import com.alibaba.excel.metadata.property.ExcelHeadProperty;
import com.alibaba.excel.read.listener.ReadListener;
import com.alibaba.excel.write.handler.WriteHandler;
import com.alibaba.excel.write.style.RowCellStyleStrategy;
import com.alibaba.excel.write.style.column.AbstractHeadColumnWidthStyleStrategy;
/**
* sheet holder
*
* @author zhuangjiaju
*/
public class SheetHolder extends AbstractWriteConfiguration {
private static final Logger LOGGER = LoggerFactory.getLogger(SheetHolder.class);
/***
* poi sheet
*/
private Sheet sheet;
/***
* sheetNo
*/
private Integer sheetNo;
/***
* sheetName
*/
private String sheetName;
/***
* poi sheet
*/
private WorkbookHolder parentWorkBook;
/***
* has been initialized table
*/
private Map<Integer, TableHolder> hasBeenInitializedTable;
/**
* current param
*/
private com.alibaba.excel.metadata.Sheet sheetParam;
public static SheetHolder buildWriteWorkSheetHolder(com.alibaba.excel.metadata.Sheet sheet,
WorkbookHolder workbookHolder) {
SheetHolder sheetHolder = buildBaseSheetHolder(sheet, workbookHolder);
sheetHolder.setNewInitialization(Boolean.TRUE);
if (sheet.getNeedHead() == null) {
sheetHolder.setNeedHead(workbookHolder.needHead());
} else {
sheetHolder.setNeedHead(sheet.getNeedHead());
}
if (sheet.getWriteRelativeHeadRowIndex() == null) {
sheetHolder.setWriteRelativeHeadRowIndex(workbookHolder.writeRelativeHeadRowIndex());
} else {
sheetHolder.setWriteRelativeHeadRowIndex(sheet.getWriteRelativeHeadRowIndex());
}
// Compatible with old code
compatibleOldCode(sheet);
List<WriteHandler> handlerList = new ArrayList<WriteHandler>();
if (sheet.getCustomWriteHandlerList() != null && !sheet.getCustomWriteHandlerList().isEmpty()) {
handlerList.addAll(sheet.getCustomWriteHandlerList());
}
// Initialization Annotation
sheetHolder.initAnnotationConfig(handlerList);
sheetHolder
.setWriteHandlerMap(sheetHolder.sortAndClearUpHandler(handlerList, workbookHolder.getWriteHandlerMap()));
Map<Class, Converter> converterMap = new HashMap<Class, Converter>(workbookHolder.getWriteConverterMap());
if (sheet.getCustomConverterList() != null && !sheet.getCustomConverterList().isEmpty()) {
for (Converter converter : sheet.getCustomConverterList()) {
converterMap.put(converter.getClass(), converter);
}
}
sheetHolder.setWriteConverterMap(converterMap);
sheetHolder.setHasBeenInitializedTable(new HashMap<Integer, TableHolder>());
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Sheet writeHandlerMap:{}", sheetHolder.getWriteHandlerMap());
}
return sheetHolder;
}
public static SheetHolder buildReadWorkSheetHolder(com.alibaba.excel.metadata.Sheet sheet,
WorkbookHolder workbookHolder) {
SheetHolder sheetHolder = buildBaseSheetHolder(sheet, workbookHolder);
if (sheet.getReadHeadRowNumber() == null) {
if (workbookHolder.getReadHeadRowNumber() == null) {
sheetHolder.setReadHeadRowNumber(sheetHolder.getExcelHeadProperty().getHeadRowNumber());
} else {
sheetHolder.setReadHeadRowNumber(workbookHolder.getReadHeadRowNumber());
}
} else {
sheetHolder.setReadHeadRowNumber(sheet.getReadHeadRowNumber());
}
Map<ConverterKey, Converter> converterMap =
new HashMap<ConverterKey, Converter>(workbookHolder.getReadConverterMap());
if (sheet.getCustomConverterList() != null && !sheet.getCustomConverterList().isEmpty()) {
for (Converter converter : sheet.getCustomConverterList()) {
converterMap.put(ConverterKey.buildConverterKey(converter), converter);
}
}
sheetHolder.setReadConverterMap(converterMap);
List<ReadListener> readListenerList = new ArrayList<ReadListener>();
if (sheet.getCustomReadListenerList() != null && !sheet.getCustomReadListenerList().isEmpty()) {
readListenerList.addAll(sheet.getCustomReadListenerList());
}
sheetHolder.setReadListenerList(readListenerList);
return sheetHolder;
}
private static SheetHolder buildBaseSheetHolder(com.alibaba.excel.metadata.Sheet sheet,
WorkbookHolder workbookHolder) {
SheetHolder sheetHolder = new SheetHolder();
sheetHolder.setSheetParam(sheet);
sheetHolder.setParentWorkBook(workbookHolder);
boolean noHead = (sheet.getHead() == null || sheet.getHead().isEmpty()) && sheet.getClazz() == null;
if (noHead) {
// Use parent
sheetHolder.setHead(workbookHolder.getHead());
sheetHolder.setClazz(workbookHolder.getClazz());
} else {
sheetHolder.setHead(sheet.getHead());
sheetHolder.setClazz(sheet.getClazz());
}
if (sheet.getAutoTrim() == null) {
workbookHolder.setAutoTrim(workbookHolder.getAutoTrim());
} else {
workbookHolder.setAutoTrim(sheet.getNeedHead());
}
// Initialization property
sheetHolder
.setExcelHeadProperty(new ExcelHeadProperty(sheetHolder.getClazz(), sheetHolder.getHead(), workbookHolder));
return sheetHolder;
}
/**
* Compatible with old code
*/
@Deprecated
private static void compatibleOldCode(com.alibaba.excel.metadata.Sheet sheet) {
if (sheet.getColumnWidthMap() != null && !sheet.getColumnWidthMap().isEmpty()) {
final Map<Integer, Integer> columnWidthMap = sheet.getColumnWidthMap();
if (sheet.getCustomWriteHandlerList() == null) {
sheet.setCustomWriteHandlerList(new ArrayList<WriteHandler>());
}
sheet.getCustomWriteHandlerList().add(new AbstractHeadColumnWidthStyleStrategy() {
@Override
protected Integer columnWidth(Head head) {
if (columnWidthMap.containsKey(head.getColumnIndex())) {
columnWidthMap.get(head.getColumnIndex());
}
return 20;
}
});
}
if (sheet.getTableStyle() != null) {
final TableStyle tableStyle = sheet.getTableStyle();
if (sheet.getCustomWriteHandlerList() == null) {
sheet.setCustomWriteHandlerList(new ArrayList<WriteHandler>());
}
CellStyle headCellStyle = new CellStyle();
headCellStyle.setFont(tableStyle.getTableHeadFont());
headCellStyle.setIndexedColors(tableStyle.getTableContentBackGroundColor());
CellStyle contentCellStyle = new CellStyle();
contentCellStyle.setFont(tableStyle.getTableContentFont());
contentCellStyle.setIndexedColors(tableStyle.getTableContentBackGroundColor());
sheet.getCustomWriteHandlerList().add(new RowCellStyleStrategy(headCellStyle, contentCellStyle));
}
}
public Sheet getSheet() {
return sheet;
}
public void setSheet(Sheet sheet) {
this.sheet = sheet;
}
public Integer getSheetNo() {
return sheetNo;
}
public void setSheetNo(Integer sheetNo) {
this.sheetNo = sheetNo;
}
public String getSheetName() {
return sheetName;
}
public void setSheetName(String sheetName) {
this.sheetName = sheetName;
}
public WorkbookHolder getParentWorkBook() {
return parentWorkBook;
}
public void setParentWorkBook(WorkbookHolder parentWorkBook) {
this.parentWorkBook = parentWorkBook;
}
public Map<Integer, TableHolder> getHasBeenInitializedTable() {
return hasBeenInitializedTable;
}
public void setHasBeenInitializedTable(Map<Integer, TableHolder> hasBeenInitializedTable) {
this.hasBeenInitializedTable = hasBeenInitializedTable;
}
public com.alibaba.excel.metadata.Sheet getSheetParam() {
return sheetParam;
}
public void setSheetParam(com.alibaba.excel.metadata.Sheet sheetParam) {
this.sheetParam = sheetParam;
}
}

138
src/main/java/com/alibaba/excel/metadata/holder/read/TableHolder.java

@ -0,0 +1,138 @@
package com.alibaba.excel.metadata.holder.read;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.metadata.CellStyle;
import com.alibaba.excel.metadata.Table;
import com.alibaba.excel.metadata.TableStyle;
import com.alibaba.excel.metadata.holder.write.AbstractWriteConfiguration;
import com.alibaba.excel.metadata.property.ExcelHeadProperty;
import com.alibaba.excel.write.handler.WriteHandler;
import com.alibaba.excel.write.style.RowCellStyleStrategy;
/**
* sheet holder
*
* @author zhuangjiaju
*/
public class TableHolder extends AbstractWriteConfiguration {
private static final Logger LOGGER = LoggerFactory.getLogger(TableHolder.class);
/***
* poi sheet
*/
private SheetHolder parentSheet;
/***
* tableNo
*/
private Integer tableNo;
/**
* current table param
*/
private Table tableParam;
public static TableHolder buildWriteWorkTableHolder(Table table, SheetHolder sheetHolder,
WorkbookHolder workbookHolder) {
TableHolder tableHolder = new TableHolder();
tableHolder.setTableParam(table);
tableHolder.setParentSheet(sheetHolder);
tableHolder.setTableNo(table.getTableNo());
boolean noHead = (table.getHead() == null || table.getHead().isEmpty()) && table.getClazz() == null;
if (noHead) {
// Use parent
tableHolder.setHead(sheetHolder.getHead());
tableHolder.setClazz(sheetHolder.getClazz());
} else {
tableHolder.setHead(table.getHead());
tableHolder.setClazz(table.getClazz());
}
tableHolder.setNewInitialization(Boolean.TRUE);
// Initialization property
tableHolder.setExcelHeadProperty(
new ExcelHeadProperty(tableHolder.getClazz(), tableHolder.getHead(), workbookHolder.getConvertAllFiled()));
if (table.getNeedHead() == null) {
tableHolder.setNeedHead(sheetHolder.needHead());
} else {
tableHolder.setNeedHead(table.getNeedHead());
}
if (table.getWriteRelativeHeadRowIndex() == null) {
tableHolder.setWriteRelativeHeadRowIndex(sheetHolder.writeRelativeHeadRowIndex());
} else {
tableHolder.setWriteRelativeHeadRowIndex(table.getWriteRelativeHeadRowIndex());
}
// Compatible with old code
compatibleOldCode(table);
List<WriteHandler> handlerList = new ArrayList<WriteHandler>();
if (table.getCustomWriteHandlerList() != null && !table.getCustomWriteHandlerList().isEmpty()) {
handlerList.addAll(table.getCustomWriteHandlerList());
}
// Initialization Annotation
tableHolder.initAnnotationConfig(handlerList);
tableHolder
.setWriteHandlerMap(tableHolder.sortAndClearUpHandler(handlerList, sheetHolder.getWriteHandlerMap()));
Map<Class, Converter> converterMap = new HashMap<Class, Converter>(sheetHolder.getWriteConverterMap());
if (table.getCustomConverterList() != null && !table.getCustomConverterList().isEmpty()) {
for (Converter converter : table.getCustomConverterList()) {
converterMap.put(converter.getClass(), converter);
}
}
tableHolder.setWriteConverterMap(converterMap);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Table writeHandlerMap:{}", tableHolder.getWriteHandlerMap());
}
return tableHolder;
}
/**
* Compatible with old code
*/
@Deprecated
private static void compatibleOldCode(Table table) {
if (table.getTableStyle() != null) {
final TableStyle tableStyle = table.getTableStyle();
if (table.getCustomWriteHandlerList() == null) {
table.setCustomWriteHandlerList(new ArrayList<WriteHandler>());
}
CellStyle headCellStyle = new CellStyle();
headCellStyle.setFont(tableStyle.getTableHeadFont());
headCellStyle.setIndexedColors(tableStyle.getTableContentBackGroundColor());
CellStyle contentCellStyle = new CellStyle();
contentCellStyle.setFont(tableStyle.getTableContentFont());
contentCellStyle.setIndexedColors(tableStyle.getTableContentBackGroundColor());
table.getCustomWriteHandlerList().add(new RowCellStyleStrategy(headCellStyle, contentCellStyle));
}
}
public SheetHolder getParentSheet() {
return parentSheet;
}
public void setParentSheet(SheetHolder parentSheet) {
this.parentSheet = parentSheet;
}
public Integer getTableNo() {
return tableNo;
}
public void setTableNo(Integer tableNo) {
this.tableNo = tableNo;
}
public Table getTableParam() {
return tableParam;
}
public void setTableParam(Table tableParam) {
this.tableParam = tableParam;
}
}

325
src/main/java/com/alibaba/excel/metadata/holder/read/WorkbookHolder.java

@ -0,0 +1,325 @@
package com.alibaba.excel.metadata.holder.read;
import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.poi.ss.usermodel.Workbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.excel.cache.ReadCache;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.converters.ConverterKey;
import com.alibaba.excel.converters.DefaultConverterLoader;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.exception.ExcelAnalysisException;
import com.alibaba.excel.metadata.holder.write.AbstractWriteConfiguration;
import com.alibaba.excel.read.listener.ModelBuildEventListener;
import com.alibaba.excel.read.listener.ReadListener;
import com.alibaba.excel.support.ExcelTypeEnum;
import com.alibaba.excel.write.handler.DefaultWriteHandlerLoader;
import com.alibaba.excel.write.handler.WriteHandler;
/**
* Workbook holder
*
* @author zhuangjiaju
*/
public class WorkbookHolder extends AbstractWriteConfiguration {
private static final Logger LOGGER = LoggerFactory.getLogger(WorkbookHolder.class);
/***
* poi Workbook
*/
private Workbook workbook;
/**
* prevent duplicate creation of sheet objects
*/
private Map<Integer, SheetHolder> hasBeenInitializedSheet;
/**
* current param
*/
private com.alibaba.excel.metadata.Workbook workbookParam;
/**
* Final output stream
*/
private OutputStream outputStream;
/**
* <li>write: Template input stream
* <li>read: Read InputStream
* <p>
* If 'inputStream' and 'file' all not empty,file first
*/
private InputStream inputStream;
/**
* <li>write: Template file
* <li>read: Read file
* <p>
* If 'inputStream' and 'file' all not empty,file first
*/
private File file;
/**
* Default true
*/
private Boolean autoCloseStream;
/**
* Excel type
*/
private ExcelTypeEnum excelType;
/**
* This object can be read in the Listener {@link AnalysisEventListener#invoke(Object, AnalysisContext)}
* {@link AnalysisContext#getCustom()}
*
*/
private Object readCustomObject;
/**
* A cache that stores temp data to save memory.Default use {@link com.alibaba.excel.cache.Ehcache}
*/
private ReadCache readCache;
/**
* true if date uses 1904 windowing, or false if using 1900 date windowing.
*
* @return
*/
private Boolean use1904windowing;
/**
* Mmandatory use 'inputStream'
*/
private Boolean mandatoryUseInputStream;
/**
* Temporary files when reading excel
*/
private File readTempFile;
/**
* The default is all excel objects.if true , you can use {@link com.alibaba.excel.annotation.ExcelIgnore} ignore a
* field. if false , you must use {@link com.alibaba.excel.annotation.ExcelProperty} to use a filed.
*
* @deprecated Just to be compatible with historical data, The default is always going to be convert all filed.
*/
@Deprecated
private Boolean convertAllFiled;
/**
* Write handler
*
* @deprecated please use {@link WriteHandler}
*/
@Deprecated
private com.alibaba.excel.event.WriteHandler writeHandler;
public static WorkbookHolder buildWriteWorkbookHolder(com.alibaba.excel.metadata.Workbook workbook) {
WorkbookHolder workbookHolder = buildBaseWorkbookHolder(workbook);
workbookHolder.setNewInitialization(Boolean.TRUE);
if (workbook.getNeedHead() == null) {
workbookHolder.setNeedHead(Boolean.TRUE);
} else {
workbookHolder.setNeedHead(workbook.getNeedHead());
}
if (workbook.getWriteRelativeHeadRowIndex() == null) {
workbookHolder.setWriteRelativeHeadRowIndex(0);
} else {
workbookHolder.setWriteRelativeHeadRowIndex(workbook.getWriteRelativeHeadRowIndex());
}
List<WriteHandler> handlerList = new ArrayList<WriteHandler>();
if (workbook.getCustomWriteHandlerList() != null && !workbook.getCustomWriteHandlerList().isEmpty()) {
handlerList.addAll(workbook.getCustomWriteHandlerList());
}
handlerList.addAll(DefaultWriteHandlerLoader.loadDefaultHandler());
workbookHolder.setWriteHandlerMap(workbookHolder.sortAndClearUpHandler(handlerList, null));
Map<Class, Converter> converterMap = DefaultConverterLoader.loadDefaultWriteConverter();
if (workbook.getCustomConverterList() != null && !workbook.getCustomConverterList().isEmpty()) {
for (Converter converter : workbook.getCustomConverterList()) {
converterMap.put(converter.getClass(), converter);
}
}
workbookHolder.setWriteConverterMap(converterMap);
workbookHolder.setHasBeenInitializedSheet(new HashMap<Integer, SheetHolder>());
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Wookbook writeHandlerMap:{}", workbookHolder.getWriteHandlerMap());
}
return workbookHolder;
}
public static WorkbookHolder buildReadWorkbookHolder(com.alibaba.excel.metadata.Workbook workbook) {
WorkbookHolder workbookHolder = buildBaseWorkbookHolder(workbook);
if (workbook.getFile() == null && workbookHolder.getInputStream() == null) {
throw new ExcelAnalysisException("Read excel 'file' and 'inputStream' cannot be empty at the same time!");
}
workbookHolder.setReadCustomObject(workbook.getReadCustomObject());
workbookHolder.setReadHeadRowNumber(workbook.getReadHeadRowNumber());
workbookHolder.setReadCache(workbook.getReadCache());
Map<ConverterKey, Converter> converterMap = DefaultConverterLoader.loadDefaultReadConverter();
if (workbook.getCustomConverterList() != null && !workbook.getCustomConverterList().isEmpty()) {
for (Converter converter : workbook.getCustomConverterList()) {
converterMap.put(ConverterKey.buildConverterKey(converter), converter);
}
}
workbookHolder.setReadConverterMap(converterMap);
List<ReadListener> readListenerList = new ArrayList<ReadListener>();
readListenerList.add(new ModelBuildEventListener());
if (workbook.getCustomReadListenerList() != null && !workbook.getCustomReadListenerList().isEmpty()) {
readListenerList.addAll(workbook.getCustomReadListenerList());
}
workbookHolder.setReadListenerList(readListenerList);
return workbookHolder;
}
private static WorkbookHolder buildBaseWorkbookHolder(com.alibaba.excel.metadata.Workbook workbook) {
WorkbookHolder workbookHolder = new WorkbookHolder();
workbookHolder.setUse1904windowing(workbook.getUse1904windowing());
workbookHolder.setWorkbookParam(workbook);
workbookHolder.setInputStream(workbook.getInputStream());
workbookHolder.setFile(workbook.getFile());
workbookHolder.setExcelType(workbook.getExcelType());
workbookHolder.setHead(workbook.getHead());
workbookHolder.setClazz(workbook.getClazz());
if (workbook.getConvertAllFiled() == null) {
workbookHolder.setConvertAllFiled(Boolean.TRUE);
} else {
workbookHolder.setConvertAllFiled(workbook.getConvertAllFiled());
}
if (workbook.getAutoCloseStream() == null) {
workbookHolder.setAutoCloseStream(Boolean.TRUE);
} else {
workbookHolder.setAutoCloseStream(workbook.getAutoCloseStream());
}
if (workbook.getAutoTrim() == null) {
workbookHolder.setAutoTrim(Boolean.TRUE);
} else {
workbookHolder.setAutoTrim(workbook.getNeedHead());
}
return workbookHolder;
}
public Workbook getWorkbook() {
return workbook;
}
public void setWorkbook(Workbook workbook) {
this.workbook = workbook;
}
public Map<Integer, SheetHolder> getHasBeenInitializedSheet() {
return hasBeenInitializedSheet;
}
public void setHasBeenInitializedSheet(Map<Integer, SheetHolder> hasBeenInitializedSheet) {
this.hasBeenInitializedSheet = hasBeenInitializedSheet;
}
public com.alibaba.excel.metadata.Workbook getWorkbookParam() {
return workbookParam;
}
public void setWorkbookParam(com.alibaba.excel.metadata.Workbook workbookParam) {
this.workbookParam = workbookParam;
}
public OutputStream getOutputStream() {
return outputStream;
}
public void setOutputStream(OutputStream outputStream) {
this.outputStream = outputStream;
}
public InputStream getInputStream() {
return inputStream;
}
public void setInputStream(InputStream inputStream) {
this.inputStream = inputStream;
}
public com.alibaba.excel.event.WriteHandler getWriteHandler() {
return writeHandler;
}
public void setWriteHandler(com.alibaba.excel.event.WriteHandler writeHandler) {
this.writeHandler = writeHandler;
}
public Boolean getAutoCloseStream() {
return autoCloseStream;
}
public void setAutoCloseStream(Boolean autoCloseStream) {
this.autoCloseStream = autoCloseStream;
}
public Boolean getConvertAllFiled() {
return convertAllFiled;
}
public void setConvertAllFiled(Boolean convertAllFiled) {
this.convertAllFiled = convertAllFiled;
}
public File getFile() {
return file;
}
public void setFile(File file) {
this.file = file;
}
public ExcelTypeEnum getExcelType() {
return excelType;
}
public void setExcelType(ExcelTypeEnum excelType) {
this.excelType = excelType;
}
public Object getReadCustomObject() {
return readCustomObject;
}
public void setReadCustomObject(Object readCustomObject) {
this.readCustomObject = readCustomObject;
}
public ReadCache getReadCache() {
return readCache;
}
public void setReadCache(ReadCache readCache) {
this.readCache = readCache;
}
public Boolean getUse1904windowing() {
return use1904windowing;
}
public void setUse1904windowing(Boolean use1904windowing) {
this.use1904windowing = use1904windowing;
}
public Boolean getMandatoryUseInputStream() {
return mandatoryUseInputStream;
}
public void setMandatoryUseInputStream(Boolean mandatoryUseInputStream) {
this.mandatoryUseInputStream = mandatoryUseInputStream;
}
public File getReadTempFile() {
return readTempFile;
}
public void setReadTempFile(File readTempFile) {
this.readTempFile = readTempFile;
}
}

5
src/main/java/com/alibaba/excel/metadata/holder/AbstractWriteConfiguration.java → src/main/java/com/alibaba/excel/metadata/holder/write/AbstractWriteConfiguration.java

@ -1,4 +1,4 @@
package com.alibaba.excel.metadata.holder;
package com.alibaba.excel.metadata.holder.write;
import java.util.ArrayList;
import java.util.HashMap;
@ -16,7 +16,8 @@ import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.converters.ConverterKey;
import com.alibaba.excel.enums.HeadKindEnum;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.event.AnalysisFinishEvent;
import com.alibaba.excel.metadata.holder.read.ReadConfiguration;
import com.alibaba.excel.read.listener.event.AnalysisFinishEvent;
import com.alibaba.excel.event.NotRepeatExecutor;
import com.alibaba.excel.event.Order;
import com.alibaba.excel.exception.ExcelAnalysisException;

2
src/main/java/com/alibaba/excel/metadata/holder/SheetHolder.java → src/main/java/com/alibaba/excel/metadata/holder/write/SheetHolder.java

@ -1,4 +1,4 @@
package com.alibaba.excel.metadata.holder;
package com.alibaba.excel.metadata.holder.write;
import java.util.ArrayList;
import java.util.HashMap;

2
src/main/java/com/alibaba/excel/metadata/holder/TableHolder.java → src/main/java/com/alibaba/excel/metadata/holder/write/TableHolder.java

@ -1,4 +1,4 @@
package com.alibaba.excel.metadata.holder;
package com.alibaba.excel.metadata.holder.write;
import java.util.ArrayList;
import java.util.HashMap;

2
src/main/java/com/alibaba/excel/metadata/holder/WorkbookHolder.java → src/main/java/com/alibaba/excel/metadata/holder/write/WorkbookHolder.java

@ -1,4 +1,4 @@
package com.alibaba.excel.metadata.holder;
package com.alibaba.excel.metadata.holder.write;
import java.io.File;
import java.io.InputStream;

2
src/main/java/com/alibaba/excel/metadata/holder/WriteConfiguration.java → src/main/java/com/alibaba/excel/metadata/holder/write/WriteConfiguration.java

@ -1,4 +1,4 @@
package com.alibaba.excel.metadata.holder;
package com.alibaba.excel.metadata.holder.write;
import java.util.List;
import java.util.Map;

2
src/main/java/com/alibaba/excel/metadata/property/ExcelHeadProperty.java

@ -23,7 +23,7 @@ import com.alibaba.excel.enums.HeadKindEnum;
import com.alibaba.excel.exception.ExcelGenerateException;
import com.alibaba.excel.metadata.CellRange;
import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.metadata.holder.WorkbookHolder;
import com.alibaba.excel.metadata.holder.write.WorkbookHolder;
import com.alibaba.excel.util.StringUtils;
/**

2
src/main/java/com/alibaba/excel/read/listener/ModelBuildEventListener.java

@ -14,7 +14,7 @@ import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.exception.ExcelDataConvertException;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.metadata.holder.ReadConfiguration;
import com.alibaba.excel.metadata.holder.read.ReadConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.alibaba.excel.metadata.property.ExcelHeadProperty;

2
src/main/java/com/alibaba/excel/read/listener/ReadListenerRegistryCenter.java

@ -2,7 +2,7 @@ package com.alibaba.excel.read.listener;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.event.AnalysisFinishEvent;
import com.alibaba.excel.read.listener.event.AnalysisFinishEvent;
/**
* Registry center.

2
src/main/java/com/alibaba/excel/event/AnalysisFinishEvent.java → src/main/java/com/alibaba/excel/read/listener/event/AnalysisFinishEvent.java

@ -1,4 +1,4 @@
package com.alibaba.excel.event;
package com.alibaba.excel.read.listener.event;
public interface AnalysisFinishEvent {
Object getAnalysisResult();

2
src/main/java/com/alibaba/excel/event/EachRowAnalysisFinishEvent.java → src/main/java/com/alibaba/excel/read/listener/event/EachRowAnalysisFinishEvent.java

@ -1,4 +1,4 @@
package com.alibaba.excel.event;
package com.alibaba.excel.read.listener.event;
import java.util.ArrayList;
import java.util.List;

2
src/main/java/com/alibaba/excel/util/WorkBookUtil.java

@ -13,7 +13,7 @@ import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import com.alibaba.excel.metadata.holder.WorkbookHolder;
import com.alibaba.excel.metadata.holder.write.WorkbookHolder;
import com.alibaba.excel.support.ExcelTypeEnum;
/**

2
src/main/java/com/alibaba/excel/write/ExcelBuilderImpl.java

@ -17,7 +17,7 @@ import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.metadata.Sheet;
import com.alibaba.excel.metadata.Table;
import com.alibaba.excel.metadata.holder.WriteConfiguration;
import com.alibaba.excel.metadata.holder.write.WriteConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.alibaba.excel.util.CollectionUtils;
import com.alibaba.excel.util.POITempFile;

4
src/main/java/com/alibaba/excel/write/handler/CellWriteHandler.java

@ -4,8 +4,8 @@ import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.metadata.holder.SheetHolder;
import com.alibaba.excel.metadata.holder.TableHolder;
import com.alibaba.excel.metadata.holder.write.SheetHolder;
import com.alibaba.excel.metadata.holder.write.TableHolder;
import com.sun.istack.internal.Nullable;
/**

4
src/main/java/com/alibaba/excel/write/handler/RowWriteHandler.java

@ -2,8 +2,8 @@ package com.alibaba.excel.write.handler;
import org.apache.poi.ss.usermodel.Row;
import com.alibaba.excel.metadata.holder.SheetHolder;
import com.alibaba.excel.metadata.holder.TableHolder;
import com.alibaba.excel.metadata.holder.write.SheetHolder;
import com.alibaba.excel.metadata.holder.write.TableHolder;
import com.sun.istack.internal.Nullable;
/**

4
src/main/java/com/alibaba/excel/write/handler/SheetWriteHandler.java

@ -1,7 +1,7 @@
package com.alibaba.excel.write.handler;
import com.alibaba.excel.metadata.holder.SheetHolder;
import com.alibaba.excel.metadata.holder.WorkbookHolder;
import com.alibaba.excel.metadata.holder.write.SheetHolder;
import com.alibaba.excel.metadata.holder.write.WorkbookHolder;
/**
* intercepts handle sheet creation

2
src/main/java/com/alibaba/excel/write/handler/WorkbookWriteHandler.java

@ -1,6 +1,6 @@
package com.alibaba.excel.write.handler;
import com.alibaba.excel.metadata.holder.WorkbookHolder;
import com.alibaba.excel.metadata.holder.write.WorkbookHolder;
/**
* intercepts handle Workbook creation

4
src/main/java/com/alibaba/excel/write/merge/AbstractMergeStrategy.java

@ -5,8 +5,8 @@ import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.metadata.holder.SheetHolder;
import com.alibaba.excel.metadata.holder.TableHolder;
import com.alibaba.excel.metadata.holder.write.SheetHolder;
import com.alibaba.excel.metadata.holder.write.TableHolder;
import com.alibaba.excel.write.handler.CellWriteHandler;
/**

6
src/main/java/com/alibaba/excel/write/style/AbstractCellStyleStrategy.java

@ -6,9 +6,9 @@ import org.apache.poi.ss.usermodel.Workbook;
import com.alibaba.excel.event.NotRepeatExecutor;
import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.metadata.holder.SheetHolder;
import com.alibaba.excel.metadata.holder.TableHolder;
import com.alibaba.excel.metadata.holder.WorkbookHolder;
import com.alibaba.excel.metadata.holder.write.SheetHolder;
import com.alibaba.excel.metadata.holder.write.TableHolder;
import com.alibaba.excel.metadata.holder.write.WorkbookHolder;
import com.alibaba.excel.write.handler.CellWriteHandler;
import com.alibaba.excel.write.handler.WorkbookWriteHandler;

4
src/main/java/com/alibaba/excel/write/style/column/AbstractColumnWidthStyleStrategy.java

@ -6,8 +6,8 @@ import org.apache.poi.ss.usermodel.Sheet;
import com.alibaba.excel.event.NotRepeatExecutor;
import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.metadata.holder.SheetHolder;
import com.alibaba.excel.metadata.holder.TableHolder;
import com.alibaba.excel.metadata.holder.write.SheetHolder;
import com.alibaba.excel.metadata.holder.write.TableHolder;
import com.alibaba.excel.write.handler.CellWriteHandler;
import com.sun.istack.internal.Nullable;

4
src/main/java/com/alibaba/excel/write/style/row/AbstractRowHeightStyleStrategy.java

@ -3,8 +3,8 @@ package com.alibaba.excel.write.style.row;
import org.apache.poi.ss.usermodel.Row;
import com.alibaba.excel.event.NotRepeatExecutor;
import com.alibaba.excel.metadata.holder.SheetHolder;
import com.alibaba.excel.metadata.holder.TableHolder;
import com.alibaba.excel.metadata.holder.write.SheetHolder;
import com.alibaba.excel.metadata.holder.write.TableHolder;
import com.alibaba.excel.write.handler.RowWriteHandler;
/**

Loading…
Cancel
Save