Browse Source

降级poi为 #587

bugfix
Jiaju Zhuang 5 years ago
parent
commit
add8b21443
  1. 4
      src/main/java/com/alibaba/excel/analysis/ExcelAnalyserImpl.java
  2. 9
      src/main/java/com/alibaba/excel/support/ExcelTypeEnum.java
  3. 6
      src/main/java/com/alibaba/excel/write/style/column/LongestMatchColumnWidthStyleStrategy.java

4
src/main/java/com/alibaba/excel/analysis/ExcelAnalyserImpl.java

@ -15,7 +15,6 @@ import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.context.AnalysisContextImpl; import com.alibaba.excel.context.AnalysisContextImpl;
import com.alibaba.excel.exception.ExcelAnalysisException; import com.alibaba.excel.exception.ExcelAnalysisException;
import com.alibaba.excel.exception.ExcelAnalysisStopException; import com.alibaba.excel.exception.ExcelAnalysisStopException;
import com.alibaba.excel.exception.ExcelGenerateException;
import com.alibaba.excel.read.metadata.ReadSheet; import com.alibaba.excel.read.metadata.ReadSheet;
import com.alibaba.excel.read.metadata.ReadWorkbook; import com.alibaba.excel.read.metadata.ReadWorkbook;
import com.alibaba.excel.read.metadata.holder.ReadWorkbookHolder; import com.alibaba.excel.read.metadata.holder.ReadWorkbookHolder;
@ -64,7 +63,8 @@ public class ExcelAnalyserImpl implements ExcelAnalyser {
if (poifsFileSystem.getRoot().hasEntry(Decryptor.DEFAULT_POIFS_ENTRY)) { if (poifsFileSystem.getRoot().hasEntry(Decryptor.DEFAULT_POIFS_ENTRY)) {
InputStream decryptedStream = null; InputStream decryptedStream = null;
try { try {
decryptedStream = DocumentFactoryHelper.getDecryptedStream(poifsFileSystem.getRoot(), null); decryptedStream =
DocumentFactoryHelper.getDecryptedStream(poifsFileSystem.getRoot().getFileSystem(), null);
excelExecutor = new XlsxSaxAnalyser(analysisContext, decryptedStream); excelExecutor = new XlsxSaxAnalyser(analysisContext, decryptedStream);
return; return;
} finally { } finally {

9
src/main/java/com/alibaba/excel/support/ExcelTypeEnum.java

@ -1,6 +1,8 @@
package com.alibaba.excel.support; package com.alibaba.excel.support;
import java.io.BufferedInputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -31,7 +33,12 @@ public enum ExcelTypeEnum {
try { try {
FileMagic fileMagic; FileMagic fileMagic;
if (file != null) { if (file != null) {
fileMagic = FileMagic.valueOf(file); BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(file));
try {
fileMagic = FileMagic.valueOf(bufferedInputStream);
} finally {
bufferedInputStream.close();
}
if (!FileMagic.OLE2.equals(fileMagic) && !FileMagic.OOXML.equals(fileMagic)) { if (!FileMagic.OLE2.equals(fileMagic) && !FileMagic.OOXML.equals(fileMagic)) {
String fileName = file.getName(); String fileName = file.getName();
if (fileName.endsWith(XLSX.getValue())) { if (fileName.endsWith(XLSX.getValue())) {

6
src/main/java/com/alibaba/excel/write/style/column/LongestMatchColumnWidthStyleStrategy.java

@ -21,7 +21,7 @@ public class LongestMatchColumnWidthStyleStrategy extends AbstractColumnWidthSty
private static final int MAX_COLUMN_WIDTH = 256; private static final int MAX_COLUMN_WIDTH = 256;
Map<Integer, Map<Integer, Integer>> cache = new HashMap<Integer, Map<Integer, Integer>>(8); private static final Map<Integer, Map<Integer, Integer>> CACHE = new HashMap<Integer, Map<Integer, Integer>>(8);
@Override @Override
protected void setColumnWidth(WriteSheetHolder writeSheetHolder, CellData cellData, Cell cell, Head head, protected void setColumnWidth(WriteSheetHolder writeSheetHolder, CellData cellData, Cell cell, Head head,
@ -29,10 +29,10 @@ public class LongestMatchColumnWidthStyleStrategy extends AbstractColumnWidthSty
if (!isHead && cellData == null) { if (!isHead && cellData == null) {
return; return;
} }
Map<Integer, Integer> maxColumnWidthMap = cache.get(writeSheetHolder.getSheetNo()); Map<Integer, Integer> maxColumnWidthMap = CACHE.get(writeSheetHolder.getSheetNo());
if (maxColumnWidthMap == null) { if (maxColumnWidthMap == null) {
maxColumnWidthMap = new HashMap<Integer, Integer>(16); maxColumnWidthMap = new HashMap<Integer, Integer>(16);
cache.put(writeSheetHolder.getSheetNo(), maxColumnWidthMap); CACHE.put(writeSheetHolder.getSheetNo(), maxColumnWidthMap);
} }
Integer columnWidth = dataLength(cellData, cell, isHead); Integer columnWidth = dataLength(cellData, cell, isHead);
if (columnWidth < 0) { if (columnWidth < 0) {

Loading…
Cancel
Save