Bug 32256 - Output .xls file unreadable when link label >= 128 characters
Summary: Output .xls file unreadable when link label >= 128 characters
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 2.5-FINAL
Hardware: All Mac OS X 10.0
: P2 normal with 4 votes (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2004-11-15 22:35 UTC by Jesse Wilson
Modified: 2006-01-17 01:21 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description Jesse Wilson 2004-11-15 22:35:25 UTC
I am using poi-2.5.1-final-20040804.jar with Microsoft Office 2004 for Mac. I have used POI to create a 
.xls file that is unreadable by Microsoft Excel.

When I attempt to open  the file created by POI, Excel reports a dialog, "Unable to read file." when I 
attempt to open it. The file is unreadable only when a hyperlink label is >= 128 characters. The exact 
same document opens fine if the hyperlink label is 127 characters or less.

See also issue 32255. In this case, POI writes the XLS file correctly without an 
ArrayIndexOutOfBoundsException. The difference between the issues is that this hyperlink points to a 
different sheet.

Here is a test program. Execute it with a 128 (or greater) character parameter to create a broken Excel 

import java.util.*;
import java.io.*;
import org.apache.poi.hssf.usermodel.*;

 * This class uses POI to create an XLS file which cannot be read by
 * Microsoft Excel.
 * @author <a href="mailto:jesse@swank.ca">Jesse Wilson</a>
public class ExcelHyperlink2 {
    public static void main(String[] args) throws IOException {
        if(args.length != 1) {
            System.out.println("Usage: ExcelHyperlink label");

        // the target sheet
        String targetSheetName = "2";
        // create a workbook, sheet, row and cell
        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet sheet1 = workbook.createSheet("1");
        HSSFRow row = sheet1.createRow((short)0);
        HSSFCell cell = row.createCell((short)0);
        // create a hyperlink in our cell, labelled by the argument
        String target = "\"#" + targetSheetName + "!B2\"";
        String label = "\"" + args[0] + "\"";
        String formula = "HYPERLINK(" + target + ", " + label + ")";

        // create a target sheet
        HSSFSheet sheet2 = workbook.createSheet(targetSheetName);

        // write the file
        FileOutputStream xlsOut = new FileOutputStream(new File("hyperlink.xls"));
Comment 1 Kyle Meadows 2006-01-09 19:46:43 UTC
I am using POI 2.5.1 final on Windows and experience the same issue. Running 
Java 1.4.2.
Comment 2 Jason Height 2006-01-17 10:21:26 UTC
Using the latest code in SVN this test case works fine.