You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2004/11/15 21:33:21 UTC
DO NOT REPLY [Bug 32255] New: -
Exception when a formula contains long strings
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=32255>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=32255
Summary: Exception when a formula contains long strings
Product: POI
Version: 2.5
Platform: All
OS/Version: Mac OS X 10.0
Status: NEW
Severity: normal
Priority: P2
Component: HSSF
AssignedTo: poi-dev@jakarta.apache.org
ReportedBy: jesse@swank.ca
I am using poi-2.5.1-final-20040804.
I create a spreadsheet which contains a Hyperlink formula. If the label that is 128 characters or less,
everything works perfectly. If the label is greater than 128 characters, an
ArrayIndexOutOfBoundsException is thrown when the workbook is written to a file.
This exception should either be not thrown at all, or thrown earler when the formula is being
constructed.
Here is the stack trace:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1645
at org.apache.poi.util.StringUtil.putCompressedUnicode(StringUtil.java:196)
at org.apache.poi.hssf.record.formula.StringPtg.writeBytes(StringPtg.java:97)
at org.apache.poi.hssf.record.FormulaRecord.serializePtgs(FormulaRecord.java:407)
at org.apache.poi.hssf.record.FormulaRecord.serialize(FormulaRecord.java:361)
at
org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate.serialize(FormulaRecordAggregate.java
:84)
at
org.apache.poi.hssf.record.aggregates.ValueRecordsAggregate.serialize(ValueRecordsAggregate.java:
153)
at org.apache.poi.hssf.model.Sheet.serialize(Sheet.java:815)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.getBytes(HSSFWorkbook.java:794)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.write(HSSFWorkbook.java:732)
at ExcelHyperlink.main(ExcelHyperlink.java:34)
Here is the test program. Run this with a single argument of length > 128 to cause the exception to be
thrown.
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 ExcelHyperlink {
public static void main(String[] args) throws IOException {
if(args.length != 1) {
System.out.println("Usage: ExcelHyperlink label");
return;
}
// create a workbook, sheet, row and cell
HSSFWorkbook workbook = new HSSFWorkbook();
String sheetName = "Page";
HSSFSheet sheet = workbook.createSheet(sheetName);
HSSFRow row = sheet.createRow((short)0);
HSSFCell cell = row.createCell((short)0);
// create a hyperlink in our cell, labelled by the argument
String target = "\"#" + sheetName + "!B2\"";
String label = "\"" + args[0] + "\"";
String formula = "HYPERLINK(" + target + ", " + label + ")";
cell.setCellFormula(formula);
// write the file
FileOutputStream xlsOut = new FileOutputStream(new File("hyperlink.xls"));
workbook.write(xlsOut);
xlsOut.close();
}
}
--
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: poi-dev-help@jakarta.apache.org