Browse Source

chore: Use Comments class instead of CommentsTable

pull/3542/head
cheehong.lee 1 year ago
parent
commit
2ea3fa23bc
  1. 19
      easyexcel-core/src/main/java/com/alibaba/excel/analysis/v07/XlsxSaxAnalyser.java

19
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.openxml4j.opc.PackagingURIHelper;
import org.apache.poi.ss.util.CellAddress; import org.apache.poi.ss.util.CellAddress;
import org.apache.poi.xssf.eventusermodel.XSSFReader; 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.CommentsTable;
import org.apache.poi.xssf.model.SharedStringsTable; import org.apache.poi.xssf.model.SharedStringsTable;
import org.apache.poi.xssf.usermodel.XSSFComment; import org.apache.poi.xssf.usermodel.XSSFComment;
@ -79,7 +80,7 @@ public class XlsxSaxAnalyser implements ExcelReadExecutor {
/** /**
* excel comments key: sheetNo value: CommentsTable * excel comments key: sheetNo value: CommentsTable
*/ */
private final Map<Integer, CommentsTable> commentsTableMap; private final Map<Integer, Comments> commentsMap;
public XlsxSaxAnalyser(XlsxReadContext xlsxReadContext, InputStream decryptedStream) throws Exception { public XlsxSaxAnalyser(XlsxReadContext xlsxReadContext, InputStream decryptedStream) throws Exception {
this.xlsxReadContext = xlsxReadContext; this.xlsxReadContext = xlsxReadContext;
@ -107,7 +108,7 @@ public class XlsxSaxAnalyser implements ExcelReadExecutor {
sheetList = new ArrayList<>(); sheetList = new ArrayList<>();
sheetMap = new HashMap<>(); sheetMap = new HashMap<>();
commentsTableMap = new HashMap<>(); commentsMap = new HashMap<>();
Map<Integer, PackageRelationshipCollection> packageRelationshipCollectionMap = MapUtils.newHashMap(); Map<Integer, PackageRelationshipCollection> packageRelationshipCollectionMap = MapUtils.newHashMap();
xlsxReadWorkbookHolder.setPackageRelationshipCollectionMap(packageRelationshipCollectionMap); xlsxReadWorkbookHolder.setPackageRelationshipCollectionMap(packageRelationshipCollectionMap);
@ -121,9 +122,9 @@ public class XlsxSaxAnalyser implements ExcelReadExecutor {
sheetList.add(new ReadSheet(index, ite.getSheetName())); sheetList.add(new ReadSheet(index, ite.getSheetName()));
sheetMap.put(index, inputStream); sheetMap.put(index, inputStream);
if (xlsxReadContext.readWorkbookHolder().getExtraReadSet().contains(CellExtraTypeEnum.COMMENT)) { if (xlsxReadContext.readWorkbookHolder().getExtraReadSet().contains(CellExtraTypeEnum.COMMENT)) {
CommentsTable commentsTable = ite.getSheetComments(); Comments comments = ite.getSheetComments();
if (null != commentsTable) { if (null != comments) {
commentsTableMap.put(index, commentsTable); commentsMap.put(index, comments);
} }
} }
if (xlsxReadContext.readWorkbookHolder().getExtraReadSet().contains(CellExtraTypeEnum.HYPERLINK)) { if (xlsxReadContext.readWorkbookHolder().getExtraReadSet().contains(CellExtraTypeEnum.HYPERLINK)) {
@ -270,14 +271,14 @@ public class XlsxSaxAnalyser implements ExcelReadExecutor {
if (!xlsxReadContext.readWorkbookHolder().getExtraReadSet().contains(CellExtraTypeEnum.COMMENT)) { if (!xlsxReadContext.readWorkbookHolder().getExtraReadSet().contains(CellExtraTypeEnum.COMMENT)) {
return; return;
} }
CommentsTable commentsTable = commentsTableMap.get(readSheet.getSheetNo()); Comments comments = commentsMap.get(readSheet.getSheetNo());
if (commentsTable == null) { if (comments == null) {
return; return;
} }
Iterator<CellAddress> cellAddresses = commentsTable.getCellAddresses(); Iterator<CellAddress> cellAddresses = comments.getCellAddresses();
while (cellAddresses.hasNext()) { while (cellAddresses.hasNext()) {
CellAddress cellAddress = cellAddresses.next(); CellAddress cellAddress = cellAddresses.next();
XSSFComment cellComment = commentsTable.findCellComment(cellAddress); XSSFComment cellComment = comments.findCellComment(cellAddress);
CellExtra cellExtra = new CellExtra(CellExtraTypeEnum.COMMENT, cellComment.getString().toString(), CellExtra cellExtra = new CellExtra(CellExtraTypeEnum.COMMENT, cellComment.getString().toString(),
cellAddress.getRow(), cellAddress.getColumn()); cellAddress.getRow(), cellAddress.getColumn());
xlsxReadContext.readSheetHolder().setCellExtra(cellExtra); xlsxReadContext.readSheetHolder().setCellExtra(cellExtra);

Loading…
Cancel
Save