Bug 65973 - Link in merged cells causes exception
Summary: Link in merged cells causes exception
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 5.2.0-FINAL
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-03-22 11:19 UTC by Jürgen Lampe
Modified: 2022-03-22 18:03 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jürgen Lampe 2022-03-22 11:19:43 UTC
Link in merged cells doesn't match the pattern CELL_REF_PATTERN in CellReference and this causes

java.lang.IllegalArgumentException: Invalid CellReference: H9:L9
	at org.apache.poi.ss.util.CellReference.separateRefParts(CellReference.java:403)
	at org.apache.poi.ss.util.CellReference.<init>(CellReference.java:118)
	at org.apache.poi.xssf.usermodel.XSSFSheet.removeOverwritten(XSSFSheet.java:3086)
	at org.apache.poi.xssf.usermodel.XSSFSheet.shiftRows(XSSFSheet.java:2975)
	at org.apache.poi.xssf.usermodel.XSSFSheet.shiftRows(XSSFSheet.java:2950)
Comment 1 PJ Fanning 2022-03-22 11:52:17 UTC
I added r1899129 which is a partial fix for case where row shifting runs into individual hyperlinks that span multiple cells. It should help in your case because your cell range is all on row 9 (H9:L9).

A workaround might be for you to iterate through the hyperlinks and replace the ones that have cell ranges with ones that are specific to 1 cell. XSSFSheet has public List<XSSFHyperlink> getHyperlinkList() which returns an unmodifiable list but you can try to use addHyperlink and removeHyperlink to add hyperlinks that are for one cell only and remove hyperlinks that are for multiple cells.
Comment 2 PJ Fanning 2022-03-22 18:03:41 UTC
I added r1899137, 1899138 and r1899139 (and a few other commits prior to this) and they seem to indicate that my changes cover some of the most obvious scenarios.