From 2ea3fa23bcc3b5d54a87b97e29b519b114b66859 Mon Sep 17 00:00:00 2001 From: "cheehong.lee" Date: Sat, 4 Nov 2023 18:50:19 +0800 Subject: [PATCH] chore: Use Comments class instead of CommentsTable --- .../excel/analysis/v07/XlsxSaxAnalyser.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) 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 5104b1e3..a0dce50d 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 @@ -41,6 +41,7 @@ import org.apache.poi.openxml4j.opc.PackageRelationshipCollection; 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; @@ -79,7 +80,7 @@ public class XlsxSaxAnalyser implements ExcelReadExecutor { /** * excel comments key: sheetNo value: CommentsTable */ - private final Map commentsTableMap; + private final Map commentsMap; public XlsxSaxAnalyser(XlsxReadContext xlsxReadContext, InputStream decryptedStream) throws Exception { this.xlsxReadContext = xlsxReadContext; @@ -107,7 +108,7 @@ public class XlsxSaxAnalyser implements ExcelReadExecutor { sheetList = new ArrayList<>(); sheetMap = new HashMap<>(); - commentsTableMap = new HashMap<>(); + commentsMap = new HashMap<>(); Map packageRelationshipCollectionMap = MapUtils.newHashMap(); xlsxReadWorkbookHolder.setPackageRelationshipCollectionMap(packageRelationshipCollectionMap); @@ -121,9 +122,9 @@ public class XlsxSaxAnalyser implements ExcelReadExecutor { sheetList.add(new ReadSheet(index, ite.getSheetName())); sheetMap.put(index, inputStream); if (xlsxReadContext.readWorkbookHolder().getExtraReadSet().contains(CellExtraTypeEnum.COMMENT)) { - CommentsTable commentsTable = ite.getSheetComments(); - if (null != commentsTable) { - commentsTableMap.put(index, commentsTable); + Comments comments = ite.getSheetComments(); + if (null != comments) { + commentsMap.put(index, comments); } } if (xlsxReadContext.readWorkbookHolder().getExtraReadSet().contains(CellExtraTypeEnum.HYPERLINK)) { @@ -270,14 +271,14 @@ public class XlsxSaxAnalyser implements ExcelReadExecutor { if (!xlsxReadContext.readWorkbookHolder().getExtraReadSet().contains(CellExtraTypeEnum.COMMENT)) { return; } - CommentsTable commentsTable = commentsTableMap.get(readSheet.getSheetNo()); - if (commentsTable == null) { + Comments comments = commentsMap.get(readSheet.getSheetNo()); + if (comments == null) { return; } - Iterator cellAddresses = commentsTable.getCellAddresses(); + Iterator cellAddresses = comments.getCellAddresses(); while (cellAddresses.hasNext()) { CellAddress cellAddress = cellAddresses.next(); - XSSFComment cellComment = commentsTable.findCellComment(cellAddress); + XSSFComment cellComment = comments.findCellComment(cellAddress); CellExtra cellExtra = new CellExtra(CellExtraTypeEnum.COMMENT, cellComment.getString().toString(), cellAddress.getRow(), cellAddress.getColumn()); xlsxReadContext.readSheetHolder().setCellExtra(cellExtra);