From ac33bd6456c2edff84ae6ef8604d8704a1a16a97 Mon Sep 17 00:00:00 2001 From: tomalloc Date: Sun, 16 Jun 2024 12:41:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E5=88=B0poi5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- easyexcel-core/pom.xml | 4 -- .../excel/analysis/v07/XlsxSaxAnalyser.java | 7 +-- .../alibaba/excel/metadata/csv/CsvCell.java | 4 -- .../excel/metadata/csv/CsvCellStyle.java | 38 ++++----------- .../alibaba/excel/metadata/csv/CsvSheet.java | 38 +++++++-------- .../excel/metadata/csv/CsvWorkbook.java | 48 ++++++++----------- .../easyexcel/test/temp/Lock2Test.java | 2 +- .../easyexcel/test/temp/StyleTest.java | 13 +---- .../test/temp/dataformat/DataFormatter1.java | 15 +++--- pom.xml | 14 ++---- 10 files changed, 65 insertions(+), 118 deletions(-) diff --git a/easyexcel-core/pom.xml b/easyexcel-core/pom.xml index 70c1e6feb..f81790036 100644 --- a/easyexcel-core/pom.xml +++ b/easyexcel-core/pom.xml @@ -28,10 +28,6 @@ org.apache.poi poi-ooxml - - org.apache.poi - poi-ooxml-schemas - org.apache.commons commons-csv diff --git a/easyexcel-core/src/main/java/com/alibaba/excel/analysis/v07/XlsxSaxAnalyser.java b/easyexcel-core/src/main/java/com/alibaba/excel/analysis/v07/XlsxSaxAnalyser.java index a2bf163db..6ea357c97 100644 --- a/easyexcel-core/src/main/java/com/alibaba/excel/analysis/v07/XlsxSaxAnalyser.java +++ b/easyexcel-core/src/main/java/com/alibaba/excel/analysis/v07/XlsxSaxAnalyser.java @@ -43,6 +43,7 @@ import org.apache.poi.openxml4j.opc.PackagingURIHelper; import org.apache.poi.ss.util.CellAddress; import org.apache.poi.xssf.eventusermodel.XSSFReader; +import org.apache.poi.xssf.model.Comments; import org.apache.poi.xssf.model.CommentsTable; import org.apache.poi.xssf.model.SharedStringsTable; import org.apache.poi.xssf.usermodel.XSSFComment; @@ -81,7 +82,7 @@ public class XlsxSaxAnalyser implements ExcelReadExecutor { /** * excel comments key: sheetNo value: CommentsTable */ - private final Map commentsTableMap; + private final Map commentsTableMap; public XlsxSaxAnalyser(XlsxReadContext xlsxReadContext, InputStream decryptedStream) throws Exception { this.xlsxReadContext = xlsxReadContext; @@ -123,7 +124,7 @@ public XlsxSaxAnalyser(XlsxReadContext xlsxReadContext, InputStream decryptedStr sheetList.add(new ReadSheet(index, ite.getSheetName())); sheetMap.put(index, inputStream); if (xlsxReadContext.readWorkbookHolder().getExtraReadSet().contains(CellExtraTypeEnum.COMMENT)) { - CommentsTable commentsTable = ite.getSheetComments(); + Comments commentsTable = ite.getSheetComments(); if (null != commentsTable) { commentsTableMap.put(index, commentsTable); } @@ -278,7 +279,7 @@ private void readComments(ReadSheet readSheet) { if (!xlsxReadContext.readWorkbookHolder().getExtraReadSet().contains(CellExtraTypeEnum.COMMENT)) { return; } - CommentsTable commentsTable = commentsTableMap.get(readSheet.getSheetNo()); + Comments commentsTable = commentsTableMap.get(readSheet.getSheetNo()); if (commentsTable == null) { return; } diff --git a/easyexcel-core/src/main/java/com/alibaba/excel/metadata/csv/CsvCell.java b/easyexcel-core/src/main/java/com/alibaba/excel/metadata/csv/CsvCell.java index 72beb30ad..fb0f51f18 100644 --- a/easyexcel-core/src/main/java/com/alibaba/excel/metadata/csv/CsvCell.java +++ b/easyexcel-core/src/main/java/com/alibaba/excel/metadata/csv/CsvCell.java @@ -227,10 +227,6 @@ public CellType getCachedFormulaResultType() { return getCellType(); } - @Override - public CellType getCachedFormulaResultTypeEnum() { - return getCellType(); - } @Override public String getCellFormula() { diff --git a/easyexcel-core/src/main/java/com/alibaba/excel/metadata/csv/CsvCellStyle.java b/easyexcel-core/src/main/java/com/alibaba/excel/metadata/csv/CsvCellStyle.java index a992f2133..85bb65242 100644 --- a/easyexcel-core/src/main/java/com/alibaba/excel/metadata/csv/CsvCellStyle.java +++ b/easyexcel-core/src/main/java/com/alibaba/excel/metadata/csv/CsvCellStyle.java @@ -76,7 +76,7 @@ public void setFont(Font font) { } @Override - public short getFontIndex() { + public int getFontIndex() { return 0; } @@ -125,10 +125,6 @@ public HorizontalAlignment getAlignment() { return null; } - @Override - public HorizontalAlignment getAlignmentEnum() { - return null; - } @Override public void setWrapText(boolean wrapped) { @@ -150,10 +146,6 @@ public VerticalAlignment getVerticalAlignment() { return null; } - @Override - public VerticalAlignment getVerticalAlignmentEnum() { - return null; - } @Override public void setRotation(short rotation) { @@ -185,10 +177,6 @@ public BorderStyle getBorderLeft() { return null; } - @Override - public BorderStyle getBorderLeftEnum() { - return null; - } @Override public void setBorderRight(BorderStyle border) { @@ -200,10 +188,6 @@ public BorderStyle getBorderRight() { return null; } - @Override - public BorderStyle getBorderRightEnum() { - return null; - } @Override public void setBorderTop(BorderStyle border) { @@ -215,10 +199,6 @@ public BorderStyle getBorderTop() { return null; } - @Override - public BorderStyle getBorderTopEnum() { - return null; - } @Override public void setBorderBottom(BorderStyle border) { @@ -230,10 +210,6 @@ public BorderStyle getBorderBottom() { return null; } - @Override - public BorderStyle getBorderBottomEnum() { - return null; - } @Override public void setLeftBorderColor(short color) { @@ -285,13 +261,14 @@ public FillPatternType getFillPattern() { return null; } + @Override - public FillPatternType getFillPatternEnum() { - return null; + public void setFillBackgroundColor(short bg) { + } @Override - public void setFillBackgroundColor(short bg) { + public void setFillBackgroundColor(Color color) { } @@ -310,6 +287,11 @@ public void setFillForegroundColor(short bg) { } + @Override + public void setFillForegroundColor(Color color) { + + } + @Override public short getFillForegroundColor() { return 0; diff --git a/easyexcel-core/src/main/java/com/alibaba/excel/metadata/csv/CsvSheet.java b/easyexcel-core/src/main/java/com/alibaba/excel/metadata/csv/CsvSheet.java index cf2cf8ecd..e15619698 100644 --- a/easyexcel-core/src/main/java/com/alibaba/excel/metadata/csv/CsvSheet.java +++ b/easyexcel-core/src/main/java/com/alibaba/excel/metadata/csv/CsvSheet.java @@ -3,8 +3,6 @@ import java.io.Closeable; import java.io.IOException; import java.math.BigDecimal; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; import java.util.Collection; import java.util.Iterator; import java.util.List; @@ -16,34 +14,15 @@ import com.alibaba.excel.exception.ExcelGenerateException; import com.alibaba.excel.util.DateUtils; import com.alibaba.excel.util.ListUtils; -import com.alibaba.excel.util.MapUtils; import com.alibaba.excel.util.NumberDataFormatterUtils; import com.alibaba.excel.util.StringUtils; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; -import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.csv.CSVFormat; import org.apache.commons.csv.CSVPrinter; -import org.apache.commons.io.ByteOrderMark; -import org.apache.poi.ss.usermodel.AutoFilter; -import org.apache.poi.ss.usermodel.Cell; -import org.apache.poi.ss.usermodel.CellRange; -import org.apache.poi.ss.usermodel.CellStyle; -import org.apache.poi.ss.usermodel.Comment; -import org.apache.poi.ss.usermodel.DataValidation; -import org.apache.poi.ss.usermodel.DataValidationHelper; -import org.apache.poi.ss.usermodel.DateUtil; -import org.apache.poi.ss.usermodel.Drawing; -import org.apache.poi.ss.usermodel.Footer; -import org.apache.poi.ss.usermodel.Header; -import org.apache.poi.ss.usermodel.Hyperlink; -import org.apache.poi.ss.usermodel.PrintSetup; -import org.apache.poi.ss.usermodel.Row; -import org.apache.poi.ss.usermodel.Sheet; -import org.apache.poi.ss.usermodel.SheetConditionalFormatting; -import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.util.CellAddress; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.PaneInformation; @@ -411,11 +390,21 @@ public double getMargin(short margin) { return 0; } + @Override + public double getMargin(PageMargin margin) { + return 0; + } + @Override public void setMargin(short margin, double size) { } + @Override + public void setMargin(PageMargin margin, double size) { + + } + @Override public boolean getProtect() { return false; @@ -481,6 +470,11 @@ public void createSplitPane(int xSplitPos, int ySplitPos, int leftmostColumn, in } + @Override + public void createSplitPane(int xSplitPos, int ySplitPos, int leftmostColumn, int topRow, PaneType activePane) { + + } + @Override public PaneInformation getPaneInformation() { return null; diff --git a/easyexcel-core/src/main/java/com/alibaba/excel/metadata/csv/CsvWorkbook.java b/easyexcel-core/src/main/java/com/alibaba/excel/metadata/csv/CsvWorkbook.java index d2f0e08b6..36fdc42cc 100644 --- a/easyexcel-core/src/main/java/com/alibaba/excel/metadata/csv/CsvWorkbook.java +++ b/easyexcel-core/src/main/java/com/alibaba/excel/metadata/csv/CsvWorkbook.java @@ -12,17 +12,10 @@ import lombok.Setter; import org.apache.commons.compress.utils.Lists; import org.apache.poi.ss.SpreadsheetVersion; +import org.apache.poi.ss.formula.EvaluationWorkbook; import org.apache.poi.ss.formula.udf.UDFFinder; -import org.apache.poi.ss.usermodel.CellStyle; -import org.apache.poi.ss.usermodel.CreationHelper; -import org.apache.poi.ss.usermodel.DataFormat; -import org.apache.poi.ss.usermodel.Font; -import org.apache.poi.ss.usermodel.Name; -import org.apache.poi.ss.usermodel.PictureData; +import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.usermodel.Row.MissingCellPolicy; -import org.apache.poi.ss.usermodel.Sheet; -import org.apache.poi.ss.usermodel.SheetVisibility; -import org.apache.poi.ss.usermodel.Workbook; /** * csv workbook @@ -200,7 +193,7 @@ public Font findFont(boolean bold, short color, short fontHeight, String name, b } @Override - public short getNumberOfFonts() { + public int getNumberOfFonts() { return 0; } @@ -209,10 +202,6 @@ public int getNumberOfFontsAsInt() { return 0; } - @Override - public Font getFontAt(short idx) { - return null; - } @Override public Font getFontAt(int idx) { @@ -272,30 +261,16 @@ public List getAllNames() { return null; } - @Override - public Name getNameAt(int nameIndex) { - return null; - } + @Override public Name createName() { return null; } - @Override - public int getNameIndex(String name) { - return 0; - } - @Override - public void removeName(int index) { - } - @Override - public void removeName(String name) { - - } @Override public void removeName(Name name) { @@ -421,6 +396,21 @@ public int addOlePackage(byte[] oleData, String label, String fileName, String c return 0; } + @Override + public EvaluationWorkbook createEvaluationWorkbook() { + return null; + } + + @Override + public CellReferenceType getCellReferenceType() { + return null; + } + + @Override + public void setCellReferenceType(CellReferenceType cellReferenceType) { + + } + @Override public Iterator iterator() { return null; diff --git a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/Lock2Test.java b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/Lock2Test.java index eba2453bd..18ed2fee0 100644 --- a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/Lock2Test.java +++ b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/Lock2Test.java @@ -26,10 +26,10 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; -import org.apache.poi.hssf.util.CellReference; import org.apache.poi.ss.usermodel.DateUtil; import org.apache.poi.ss.usermodel.FillPatternType; import org.apache.poi.ss.usermodel.IndexedColors; +import org.apache.poi.ss.util.CellReference; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.slf4j.Logger; diff --git a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/StyleTest.java b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/StyleTest.java index 509dc57ea..284caa6c7 100644 --- a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/StyleTest.java +++ b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/StyleTest.java @@ -10,21 +10,12 @@ import com.alibaba.excel.EasyExcel; import com.alibaba.fastjson2.JSON; -import org.apache.poi.hssf.usermodel.HSSFDateUtil; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.poifs.crypt.Decryptor; import org.apache.poi.poifs.filesystem.POIFSFileSystem; -import org.apache.poi.ss.usermodel.BuiltinFormats; -import org.apache.poi.ss.usermodel.Cell; -import org.apache.poi.ss.usermodel.DataFormatter; -import org.apache.poi.ss.usermodel.DateUtil; -import org.apache.poi.ss.usermodel.ExcelStyleDateFormatter; -import org.apache.poi.ss.usermodel.Row; -import org.apache.poi.ss.usermodel.Sheet; -import org.apache.poi.ss.usermodel.Workbook; -import org.apache.poi.ss.usermodel.WorkbookFactory; +import org.apache.poi.ss.usermodel.*; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -180,7 +171,7 @@ public void testFormatter3() throws Exception { private void isDate(Cell cell) { System.out.println( DateUtil.isADateFormat(cell.getCellStyle().getDataFormat(), cell.getCellStyle().getDataFormatString())); - System.out.println(HSSFDateUtil.isCellDateFormatted(cell)); + System.out.println(DateUtil.isCellDateFormatted(cell)); DataFormatter f = new DataFormatter(); System.out.println(f.formatCellValue(cell)); diff --git a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/dataformat/DataFormatter1.java b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/dataformat/DataFormatter1.java index 6af972ef1..3fccb3bd2 100644 --- a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/dataformat/DataFormatter1.java +++ b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/dataformat/DataFormatter1.java @@ -38,6 +38,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import com.alibaba.easyexcel.test.temp.Lock2Test; import org.apache.poi.ss.format.CellFormat; import org.apache.poi.ss.format.CellFormatResult; import org.apache.poi.ss.formula.ConditionalFormattingEvaluator; @@ -54,8 +55,9 @@ import org.apache.poi.ss.util.DateFormatConverter; import org.apache.poi.ss.util.NumberToTextConverter; import org.apache.poi.util.LocaleUtil; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * DataFormatter contains methods for formatting the value stored in an Cell. This can be useful for reports and GUI @@ -245,8 +247,7 @@ void checkForLocaleChange(Locale newLocale) { /** * For logging any problems we find */ - private static POILogger logger = POILogFactory.getLogger(DataFormatter.class); - + private static final Logger logger = LoggerFactory.getLogger(DataFormatter.class); /** * Creates a formatter using the {@link Locale#getDefault() default locale}. */ @@ -358,7 +359,7 @@ private Format getFormat(double cellValue, int formatIndex, String formatStrIn) // Wrap and return (non-cachable - CellFormat does that) return new CellFormatResultWrapper(cfmt.apply(cellValueO)); } catch (Exception e) { - logger.log(POILogger.WARN, "Formatting failed for format " + formatStr + ", falling back", e); + logger.warn("Formatting failed for format " + formatStr + ", falling back", e); } } @@ -598,7 +599,7 @@ private Format createDateFormat(String pFormatStr, double cellValue) { try { return new ExcelStyleDateFormatter(formatStr, dateSymbols); } catch (IllegalArgumentException iae) { - logger.log(POILogger.DEBUG, "Formatting failed for format " + formatStr + ", falling back", iae); + logger.debug("Formatting failed for format " + formatStr + ", falling back", iae); // the pattern could not be parsed correctly, // so fall back to the default number format return getDefaultFormat(cellValue); @@ -759,7 +760,7 @@ private Format createNumberFormat(String formatStr, double cellValue) { try { return new InternalDecimalFormatWithScale(format, symbols); } catch (IllegalArgumentException iae) { - logger.log(POILogger.DEBUG, "Formatting failed for format " + formatStr + ", falling back", iae); + logger.debug("Formatting failed for format " + formatStr + ", falling back", iae); // the pattern could not be parsed correctly, // so fall back to the default number format return getDefaultFormat(cellValue); diff --git a/pom.xml b/pom.xml index 358a28464..92742a013 100644 --- a/pom.xml +++ b/pom.xml @@ -20,6 +20,7 @@ + 5.2.3 3.3.4 UTF-8 1.8 @@ -96,22 +97,17 @@ org.apache.poi poi - 4.1.2 + ${poi.version} org.apache.poi poi-ooxml - 4.1.2 - - - org.apache.poi - poi-ooxml-schemas - 4.1.2 + ${poi.version} org.apache.commons commons-csv - 1.8 + 1.10.0 org.slf4j @@ -131,7 +127,7 @@ commons-io commons-io - 2.11.0 + 2.15.0