Hi, the example you attached contains rich text cells which we do not support as yet.  Rich text cells have multiple fonts/colors/styles within the one cell.
 
Regards,
 
Glen Stampoultzis  (TriNexus Pty Ltd)
+63 3 9753-6850     0402 835 458
ICQ:  62722370    EMail:  [EMAIL PROTECTED]
 
----- Original Message -----
Sent: Sunday, April 14, 2002 12:51 PM
Subject: Re: Can not create HSSFWorkbook for the file attached - Next error...

Thank you - now i have time to try this patch (with jakarta-poi 1.5.0-dev from 14. Apr.) and it works with my example. I change my example and add some Values in the next row. Now I get the next error:

        POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream("S:\\POI\\test.xls"));
        System.out.println("Open Workbook");
        HSSFWorkbook wb = new HSSFWorkbook(fs);
        HSSFSheet sheet = wb.getSheetAt(0);



New Error:
java.lang.reflect.InvocationTargetException: java.lang.ClassCastException: org.apache.poi.hssf.record.SSTRecord$UnicodeStringHolder

    at org.apache.poi.hssf.record.UnicodeString.compareTo(UnicodeString.java:336)

    at org.apache.poi.util.BinaryTree.compare(BinaryTree.java:558)

    at org.apache.poi.util.BinaryTree.lookup(BinaryTree.java:530)

    at org.apache.poi.util.BinaryTree.doGet(BinaryTree.java:490)

    at org.apache.poi.util.BinaryTree.getKeyForValue(BinaryTree.java:210)

    at org.apache.poi.hssf.record.SSTRecord.processString(SSTRecord.java:1053)

    at org.apache.poi.hssf.record.SSTRecord.manufactureStrings(SSTRecord.java:979)

    at org.apache.poi.hssf.record.SSTRecord.fillFields(SSTRecord.java:837)

    at org.apache.poi.hssf.record.Record.fillFields(Record.java:142)

    at org.apache.poi.hssf.record.Record.<init>(Record.java:104)

    at org.apache.poi.hssf.record.SSTRecord.<init>(SSTRecord.java:161)

    at java.lang.reflect.Constructor.newInstance(Native Method)

    at org.apache.poi.hssf.record.RecordFactory.createRecord(RecordFactory.java:211)

    at org.apache.poi.hssf.record.RecordFactory.createRecords(RecordFactory.java:149)

    at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:140)

    at unbenannt6.Unbenannt1.<init>(Unbenannt1.java:30)

    at unbenannt6.Unbenannt1.main(Unbenannt1.java:53)

org.apache.poi.hssf.record.RecordFormatException: Unable to construct record instance, the following exception occured: null

    at org.apache.poi.hssf.record.RecordFactory.createRecord(RecordFactory.java:224)

    at org.apache.poi.hssf.record.RecordFactory.createRecords(RecordFactory.java:149)

    at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:140)

    at unbenannt6.Unbenannt1.<init>(Unbenannt1.java:30)

    at unbenannt6.Unbenannt1.main(Unbenannt1.java:53)



Glen Stampoultzis wrote:
Okay, here's a patch that gets arround the problem.  The patch is a major
hack and will not be put into CVS ever ever ever. However it should get
past your problem.

What I really need to determine is how duplicates got into the SST record to
begin with.

-- Glen

----- Original Message -----
From: "Stefan Neudorfer" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, April 02, 2002 5:03 AM
Subject: Re: Can not create HSSFWorkbook for the file attached


Version - it's a good question. I get this file from our partners in
italy. I changed it and saved it with Star Office (5.2) - the version
which I send to you. But I get the same error with the original File.
This was my first try to look what I can do again this error.


Glen Stampoultzis wrote:

Hi, it appears that there are duplicate string entries in the SSTRecord.
Which version of Excel was this file created with?

-- Glen

----- Original Message -----
From: "Stefan Neudorfer" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, April 01, 2002 2:02 PM
Subject: Re: Can not create HSSFWorkbook for the file attached


We get the same error with the first try with our file and now we search
about a workarrount for this bug. I check our version, it is the newest
version from POI.

We have to import some files like this file into our database and we
hope POI can help us that we never have to make some CSV-files before we
can work with this data.




Iouri Michtchenko wrote:

Could anybody test this file?
When I do :

HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream("test.xls"));

It throws an exception:

net.sourceforge.poi.hssf.record.RecordFormatException: Unable to

construct

record instance
net.sourceforge.poi.hssf.record.Record[]
net.sourceforge.poi.hssf.record.RecordFactory.createRecord(short,
short,
byte[]) (RecordFactory.java:271)
java.util.List

net.sourceforge.poi.hssf.record.RecordFactory.createRecords(java.io.InputS
t
r

eam) (RecordFactory.java:202)
void

net.sourceforge.poi.hssf.usermodel.HSSFWorkbook.<init>(net.sourceforge.poi
.
p

oifs.filesystem.POIFSFileSystem) (HSSFWorkbook.java:156)
void

net.sourceforge.poi.hssf.usermodel.HSSFWorkbook.<init>(java.io.InputStream
)
(HSSFWorkbook.java:191)

Thanks.

--
Stefan Neudorfer
E-Mail: [EMAIL PROTECTED]
Tel.: 0049 89 688 00 622
Fax.: 0049 89 688 00 669


Firma:
Stefan Th. Neudorfer Software & Consulting GmbH
Klack-Redaktion
Turner Str. 64
81827 M�nchen
Germany
Web.: http://www.neudorfer.de
TV-Magazin: http://www.klack.com







--
Stefan Neudorfer
E-Mail: [EMAIL PROTECTED]
Tel.: 0049 89 688 00 622
Fax.: 0049 89 688 00 669


Firma:
Stefan Th. Neudorfer Software & Consulting GmbH
Klack-Redaktion
Turner Str. 64
81827 M�nchen
Germany
Web.: http://www.neudorfer.de
TV-Magazin: http://www.klack.com





Index: org/apache/poi/hssf/record/SSTRecord.java
===================================================================
RCS file: /home/cvs/jakarta-poi/src/java/org/apache/poi/hssf/record/SSTRecord.java,v
retrieving revision 1.2
diff -u -r1.2 SSTRecord.java
--- org/apache/poi/hssf/record/SSTRecord.java 11 Feb 2002 10:45:50 -0000 1.2
+++ org/apache/poi/hssf/record/SSTRecord.java 2 Apr 2002 04:03:46 -0000
@@ -105,6 +105,10 @@
LittleEndianConsts.SHORT_SIZE + LittleEndianConsts.BYTE_SIZE;
public static final short sid = 0xfc;

+ // Indicates a duplication - this is a major hack until we can figure a better solution to this
+ // problem.
+ public static final String DUPLICATE = "$$##DUPLICATE";
+
// union of strings in the SST and EXTSST
private int field_1_num_strings;

@@ -182,7 +186,7 @@
* whether 16-bit encoding must be used.
* <p>
* THIS IS THE PREFERRED METHOD OF ADDING A STRING. IF YOU USE THE
- * OTHER ,code>addString</code> METHOD AND FORCE 8-BIT ENCODING ON
+ * OTHER <code>addString</code> METHOD AND FORCE 8-BIT ENCODING ON
* A STRING THAT SHOULD USE 16-BIT ENCODING, YOU WILL CORRUPT THE
* STRING; IF YOU USE THAT METHOD AND FORCE 16-BIT ENCODING, YOU
* ARE WASTING SPACE WHEN THE WORKBOOK IS WRITTEN OUT.
@@ -329,13 +333,23 @@

public String getString(final int id)
{
- return (( UnicodeString ) field_3_strings.get(new Integer(id)))
- .getString();
+ return getUnicodeString(id).toString();
+ }
+
+ private UnicodeString getUnicodeString(final int id)
+ {
+ Integer key = new Integer(id);
+
+ Object obj = field_3_strings.get(key);
+ if (obj instanceof UnicodeString)
+ return (UnicodeString)obj;
+ else
+ return ((UnicodeStringHolder)obj).value;
}

public boolean getString16bit(final int id)
{
- return ((( UnicodeString ) field_3_strings.get(new Integer(id)))
+ return (getUnicodeString(id)
.getOptionFlags() == 1);
}

@@ -357,8 +371,7 @@
for (int k = 0; k < field_3_strings.size(); k++)
{
buffer.append(" .string_" + k + " = ")
- .append((( UnicodeString ) field_3_strings
- .get(new Integer(k))).toString()).append("\n");
+ .append(getUnicodeString(k).toString()).append("\n");
}
buffer.append("[/SST]\n");
return buffer.toString();
@@ -389,7 +402,7 @@
byte[] stringreminant = null;
int unipos = 0;
boolean lastneedcontinue = false;
- int stringbyt eswritten = 0;
+// int stringbyteswritten = 0;
boolean first_record = true;
int totalWritten = 0;
int size = 0;
@@ -416,9 +429,9 @@
else
{
pos = 0;
- int to_be_written = (unicodesize - stringbyteswritten)
- + (lastneedcontinue ? 1
- : 0); // not used?
+// int to_be_written = (unicodesize - stringbyteswritten)
+// + (lastneedcontinue ? 1
+// : 0); // not used?

size =
(( Integer ) _record_lengths
@@ -444,7 +457,7 @@
System.arraycopy(stringreminant, 0, data ,
pos + offset + totalWritten,
stringreminant.length);
- stringbyteswritten += stringreminant.length - 1;
+// stringbyteswritten += stringreminant.length - 1;
pos += stringreminant.length;
lastneedcontinue = false;
available -= stringreminant.length;
@@ -456,7 +469,7 @@
System.arraycopy(stringreminant, 0, data,
pos + offset + totalWritten,
available);
- stringbyteswritten += available - 1;
+// stringbyteswritten += available - 1;
pos += available;
byte[] leftover =
new byte[ (stringreminant.length - available) + LittleEndianConsts.BYTE_SIZE ];
@@ -476,16 +489,16 @@
// some more strings
for (; unipos < field_3_strings.size(); unipos++)
{
- Integer intunipos = new Integer(unipos);
+// Integer intunipos = new Integer(unipos);
UnicodeString unistr =
- (( UnicodeString ) field_3_strings.get(intunipos));
+ getUnicodeString(unipos);

if (unistr.getRecordSize() <= available)
{
unistr.serialize(pos + offset + totalWritten, data);
int rsize = unistr.getRecordSize();

- stringbyteswritten += rsize;
+// stringbyteswritten += rsize;
pos + = rsize;
available -= rsize;
}
@@ -502,7 +515,7 @@
System.arraycopy(ucs, 0, data,
pos + offset + totalWritten,
available);
- stringbyteswritten += available;
+// stringbyteswritten += available;
stringreminant =
new byte[ (ucs.length - available) + LittleEndianConsts.BYTE_SIZE ];
System.arraycopy(ucs, available, stringreminant,
@@ -524,7 +537,7 @@
{

// short data: write one simple SST record
- int datasize = _sst_record_overhead + unicodesize; // not used?
+// int datasize = _sst_record_overhead + unicodesize; // not used?

writeSSTHeader(
data, 0 + offset,
@@ -536,7 +549,7 @@
for (int k = 0; k < field_3_strings.size(); k++)
{
UnicodeString unistr =
- (( UnicodeString ) field_3_strings.get(new Integer(k)));
+ getUnicodeString(k);

System.arraycopy(unistr.serialize(), 0, data, pos + offset,
unistr.getRecordSize());
@@ -546,20 +559,6 @@
return rval;
}

- // not used: remove?
- private int calculateStringsize()
- {
- int retval = 0;
-
- for (int k = 0; k < field_3_strings.size(); k++)
- {
- retval +=
- (( UnicodeString ) field_3_strings.get(new Integer(k)))
- .getRecordSize();
- }
- return retval;
- }
-
/**
* Process a Continue record. A C ontinue record for an SST record
* contains the same kind of data that the SST record contains,
@@ -911,16 +910,16 @@
return offset - pos;
}

- private int calculateUCArrayLength(final byte [][] ucarray)
- {
- int retval = 0;
-
- for (int k = 0; k < ucarray.length; k++)
- {
- retval += ucarray[ k ].length;
- }
- return retval;
- }
+// private int calculateUCArrayLength(final byte [][] ucarray)
+// {
+// int retval = 0;
+//
+// for (int k = 0; k < ucarray.length; k++)
+// {
+// retval += ucarray[ k ].length;
+// }
+// return retval;
+// }

private void manufactureStrings(final byte [] data, final int index,
short size)
@@ -1029,8 +1028,15 @@
else
{
Integer integer = new Integ er(field_3_strings.size());
-
- field_3_strings.put(integer, string);
+ if (field_3_strings.getKeyForValue(string) == null)
+ {
+ field_3_strings.put(integer, string);
+ }
+ else
+ {
+ UnicodeStringHolder holder = new UnicodeStringHolder(string);
+ field_3_strings.put(integer, holder);
+ }
}
}

@@ -1142,10 +1148,10 @@
for (; unipos < field_3_strings.size(); unipos++)
{
int available = _max - pos;
- Integer intunipos = new Integer(unipos);
+// Integer intunipos = new Integer(unipos);

unistr =
- (( UnicodeString ) field_3_strings.get(intunipos));
+ getUnicodeString(unipos);
if (unist r.getRecordSize() <= available)
{
stringbyteswritten += unistr.getRecordSize();
@@ -1210,10 +1216,84 @@
for (int k = 0; k < field_3_strings.size(); k++)
{
UnicodeString string =
- ( UnicodeString ) field_3_strings.get(new Integer(k));
+ getUnicodeString(k);

retval += string.getRecordSize();
}
return retval;
+ }
+
+ private class UnicodeStringHolder
+ implements Comparable
+ {
+ public UnicodeString value;
+
+ public UnicodeStringHolder(UnicodeString value)
+ {
+ this.value = value;
+ }
+
+ /**
+ * Compares this object with the specified object for order. Returns a
+ * negative integer, zero, or a positive integer as this object is less
+ * than, equal to, or gr eater than the specified object.<p>
+ *
+ * The implementor must ensure <tt>sgn(x.compareTo(y)) ==
+ * -sgn(y.compareTo(x))</tt> for all <tt>x</tt> and <tt>y</tt>. (This
+ * implies that <tt>x.compareTo(y)</tt> must throw an exception iff
+ * <tt>y.compareTo(x)</tt> throws an exception.)<p>
+ *
+ * The implementor must also ensure that the relation is transitive:
+ * <tt>(x.compareTo(y)&gt;0 &amp;&amp; y.compareTo(z)&gt;0)</tt> implies
+ * <tt>x.compareTo(z)&gt;0</tt>.<p>
+ *
+ * Finally, the implementer must ensure that <tt>x.compareTo(y)==0</tt>
+ * implies that <tt>sgn(x.compareTo(z)) == sgn(y.compareTo(z))</tt>, for
+ * all <tt>z</tt>.<p>
+ *
+ * I t is strongly recommended, but <i>not</i> strictly required that
+ * <tt>(x.compareTo(y)==0) == (x.equals(y))</tt>. Generally speaking, any
+ * class that implements the <tt>Comparable</tt> interface and violates
+ * this condition should clearly indicate this fact. The recommended
+ * language is "Note: this class has a natural ordering that is
+ * inconsistent with equals."
+ *
+ * @param o the Object to be compared.
+ * @return a negative integer, zero, or a positive integer as this object
+ * is less than, equal to, or greater than the specified object.
+ *
+ * @throws ClassCastException if the specified object's type prevents it
+ * from being compared to this Object.
+ */
+ public int compareTo(Object o)
+ {
+ return 1;
+ }
+
+ /**
+ * Returns a string representation of the object. In general, the
+ * <code>toString</code> method returns a string that
+ * "textually represents" this object. The result should
+ * be a concise but informative representation that is easy for a
+ * person to read.
+ * It is recommended that all subclasses override this method.
+ * <p>
+ * The <code>toString</code> method for class <code>Object</code>
+ * returns a string consisting of the name of the class of which the
+ * object is an instance, the at-sign character `<code>@</code>', and
+ * the unsigned hexadecimal representation of the hash code of the
+ * object. In other words, this method returns a string equal to the
+ * value of:
+ * <blockquote>
+ * <pre>
+ * getClass() .getName() + '@' + Integer.toHexString(hashCode())
+ * </pre></blockquote>
+ *
+ * @return a string representation of the object.
+ */
+ public String toString()
+ {
+ return value.toString();
+ }
}
}
Index: org/apache/poi/hssf/record/UnicodeString.java
===================================================================
RCS file: /home/cvs/jakarta-poi/src/java/org/apache/poi/hssf/record/UnicodeString.java,v
retrieving revision 1.2
diff -u -r1.2 UnicodeString.java
--- org/apache/poi/hssf/record/UnicodeString.java 11 Feb 2002 10:45:50 -0000 1.2
+++ org/apache/poi/hssf/record/UnicodeString.java 2 Apr 2002 04:03:46 -0000
@@ -333,9 +333,16 @@

public int compareTo(Object obj)
{
- UnicodeString str = ( UnicodeString ) obj;
+ if (obj instanceof UnicodeString)
+ {
+ UnicodeString str = ( UnicodeString ) obj;

- return this.getString().compareTo(str.getString());
+ return this.getString().compareTo(str.getString());
+ }
+ else
+ {
+ return 1;
+ }
}

int maxBrokenLength(final int proposedBrokenLength)


-- 
Stefan Neudorfer
E-Mail: [EMAIL PROTECTED]
Tel.: 0049 89 688 00 622
Fax.: 0049 89 688 00 669


Firma:
Stefan Th. Neudorfer Software & Consulting GmbH
Klack-Redaktion
Turner Str. 64
81827 M�nchen
Germany
Web.: http://www.neudorfer.de
TV-Magazin: http://www.klack.com

Reply via email to