Bug 47504 - xlsx files with hyperlinks to document locations gives error: A segment shall not hold any characters other than pchar characters. [M1.6]
Summary: xlsx files with hyperlinks to document locations gives error: A segment shall...
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.5-dev
Hardware: All All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-07-09 16:21 UTC by Leif Nelson
Modified: 2009-07-12 00:39 UTC (History)
0 users



Attachments
sample workbook that POI 3.5-beta6 cannot open (29.34 KB, application/octet-stream)
2009-07-09 16:21 UTC, Leif Nelson
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Leif Nelson 2009-07-09 16:21:14 UTC
Created attachment 23953 [details]
sample workbook that POI 3.5-beta6 cannot open

Problem:

I created a simple xlsx file (Tried using both Excel 2008/Mac and 2007/Windows) by doing the following:
1) Create new workbook
2) Add a shape to workbook (Insert->Picture->Shape)
3) Right-click the shape, select Hyperlink...
4) Select "Document" (or "Place in this Document") as the link type
5) Click "Locate..." choose "Cell Reference", then select a cell on a sheet
6) Save file

(I will attach this workbook to the bug)

Try to read the xlsx file with POI (3.5-beta6), using the following code:

     XSSFWorkbook wb = new XSSFWorkbook("test-hyperlink.xlsx");

Get the following exception:

Exception in thread "main" org.apache.poi.POIXMLException: org.apache.poi.openxml4j.exceptions.InvalidFormatException: A segment shall not hold any characters other than pchar characters. [M1.6]
	at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:152)
	at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:163)
	at org.apache.poi.util.TestLoad.main(TestLoad.java:49)
Caused by: org.apache.poi.openxml4j.exceptions.InvalidFormatException: A segment shall not hold any characters other than pchar characters. [M1.6]
	at org.apache.poi.openxml4j.opc.PackagePartName.checkPCharCompliance(PackagePartName.java:370)
	at org.apache.poi.openxml4j.opc.PackagePartName.throwExceptionIfPartNameHaveInvalidSegments(PackagePartName.java:270)
	at org.apache.poi.openxml4j.opc.PackagePartName.throwExceptionIfInvalidPartUri(PackagePartName.java:185)
	at org.apache.poi.openxml4j.opc.PackagePartName.<init>(PackagePartName.java:83)
	at org.apache.poi.openxml4j.opc.PackagingURIHelper.createPartName(PackagingURIHelper.java:443)
	at org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:234)
	at org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:244)
	at org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:244)
	at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:150)
	... 2 more
Comment 1 Yegor Kozlov 2009-07-12 00:39:44 UTC
Fixed in r793280
POI didn't properly process OPC packages containing relationships with targets starting with '#'.

In your case the problem was caused by a hyperlink relationship attached to the sheet drawing:

  <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" Target="#Sheet1!A1"/>

The '#' character indicates an internal target (e.g. cell region).  

Regards,
Yegor