Found a case where the shared formula does not resolve. This was in the test case for the org.apache.poi.hssf.record.formula.eval.TextEverything
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@437126 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6759fe7790
commit
76a2ebcf6e
@ -95,7 +95,7 @@ public class RecordInputStream extends InputStream
|
|||||||
|
|
||||||
public void nextRecord() throws RecordFormatException {
|
public void nextRecord() throws RecordFormatException {
|
||||||
if ((currentLength != -1) && (currentLength != recordOffset)) {
|
if ((currentLength != -1) && (currentLength != recordOffset)) {
|
||||||
System.out.println("WARN. Unread "+remaining()+" bytes of record "+Integer.toHexString(currentSid));
|
System.out.println("WARN. Unread "+remaining()+" bytes of record 0x"+Integer.toHexString(currentSid));
|
||||||
}
|
}
|
||||||
currentSid = nextSid;
|
currentSid = nextSid;
|
||||||
pos += LittleEndian.SHORT_SIZE;
|
pos += LittleEndian.SHORT_SIZE;
|
||||||
@ -111,7 +111,7 @@ public class RecordInputStream extends InputStream
|
|||||||
//Read the Sid of the next record
|
//Read the Sid of the next record
|
||||||
nextSid = LittleEndian.readShort(in);
|
nextSid = LittleEndian.readShort(in);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
throw new RecordFormatException("Error reading bytes");
|
throw new RecordFormatException("Error reading bytes", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -226,7 +226,7 @@ public class RecordInputStream extends InputStream
|
|||||||
* length)
|
* length)
|
||||||
*/
|
*/
|
||||||
public String readUnicodeLEString(int length) {
|
public String readUnicodeLEString(int length) {
|
||||||
if ((length < 0) || ((remaining() / 2) < length)) {
|
if ((length < 0) || (((remaining() / 2) < length) && !isContinueNext())) {
|
||||||
throw new IllegalArgumentException("Illegal length");
|
throw new IllegalArgumentException("Illegal length");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,7 +239,7 @@ public class RecordInputStream extends InputStream
|
|||||||
}
|
}
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String readCompressedUnicode(int length) {
|
public String readCompressedUnicode(int length) {
|
||||||
if ((length < 0) || (remaining() < length)) {
|
if ((length < 0) || (remaining() < length)) {
|
||||||
throw new IllegalArgumentException("Illegal length");
|
throw new IllegalArgumentException("Illegal length");
|
||||||
@ -258,10 +258,20 @@ public class RecordInputStream extends InputStream
|
|||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Returns an excel style unicode string from the bytes reminaing in the record.
|
||||||
|
* <i>Note:</i> Unicode strings differ from <b>normal</b> strings due to the addition of
|
||||||
|
* formatting information.
|
||||||
|
*
|
||||||
|
* @return The unicode string representation of the remaining bytes.
|
||||||
|
*/
|
||||||
public UnicodeString readUnicodeString() {
|
public UnicodeString readUnicodeString() {
|
||||||
return new UnicodeString(this);
|
return new UnicodeString(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Returns the remaining bytes for the current record.
|
||||||
|
*
|
||||||
|
* @return The remaining bytes of the current record.
|
||||||
|
*/
|
||||||
public byte[] readRemainder() {
|
public byte[] readRemainder() {
|
||||||
int size = remaining();
|
int size = remaining();
|
||||||
byte[] result = new byte[size];
|
byte[] result = new byte[size];
|
||||||
@ -293,10 +303,18 @@ public class RecordInputStream extends InputStream
|
|||||||
return out.toByteArray();
|
return out.toByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** The remaining number of bytes in the <i>current</i> record.
|
||||||
|
*
|
||||||
|
* @return The number of bytes remaining in the current record
|
||||||
|
*/
|
||||||
public int remaining() {
|
public int remaining() {
|
||||||
return (currentLength - recordOffset);
|
return (currentLength - recordOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Returns true iif a Continue record is next in the excel stream
|
||||||
|
*
|
||||||
|
* @return True when a ContinueRecord is next.
|
||||||
|
*/
|
||||||
public boolean isContinueNext() {
|
public boolean isContinueNext() {
|
||||||
return (nextSid == ContinueRecord.sid);
|
return (nextSid == ContinueRecord.sid);
|
||||||
}
|
}
|
||||||
|
@ -154,28 +154,14 @@ public class ValueRecordsAggregate
|
|||||||
if (shrd.isFormulaInShared(formula)) {
|
if (shrd.isFormulaInShared(formula)) {
|
||||||
shrd.convertSharedFormulaRecord(formula);
|
shrd.convertSharedFormulaRecord(formula);
|
||||||
found = true;
|
found = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found)
|
if (!found) {
|
||||||
throw new RecordFormatException("Could not find appropriate shared formula");
|
//Sometimes the shared formula flag "seems" to be errornously set,
|
||||||
/*
|
//cant really do much about that.
|
||||||
|
//throw new RecordFormatException("Could not find appropriate shared formula");
|
||||||
if ((lastSharedFormula != null) && (lastSharedFormula.isFormulaInShared(formula))) {
|
}
|
||||||
//Convert this Formula Record from a shared formula to a real formula
|
|
||||||
lastSharedFormula.convertSharedFormulaRecord(formula);
|
|
||||||
} else {
|
|
||||||
if (nextRecord instanceof SharedFormulaRecord) {
|
|
||||||
//Handle the SharedFormulaRecord and move on.
|
|
||||||
k++;
|
|
||||||
lastSharedFormula = (SharedFormulaRecord) nextRecord;
|
|
||||||
|
|
||||||
//Convert this Formula Record from a shared formula to a real formula
|
|
||||||
lastSharedFormula.convertSharedFormulaRecord(formula);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
throw new RuntimeException(
|
|
||||||
"Shared formula bit set but next record is not a Shared Formula??");
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lastFormulaAggregate = new FormulaRecordAggregate((FormulaRecord)rec, null);
|
lastFormulaAggregate = new FormulaRecordAggregate((FormulaRecord)rec, null);
|
||||||
|
@ -23,18 +23,10 @@ import org.apache.poi.hssf.util.CellReference;
|
|||||||
*/
|
*/
|
||||||
public class GenericFormulaTestCase extends TestCase {
|
public class GenericFormulaTestCase extends TestCase {
|
||||||
|
|
||||||
protected static final String FILENAME = System.getProperty("HSSF.testdata.path")+ "/FormulaEvalTestData.xls";
|
protected final String FILENAME = System.getProperty("HSSF.testdata.path")+ "/FormulaEvalTestData.xls";
|
||||||
|
|
||||||
|
protected HSSFWorkbook workbook = null;
|
||||||
|
|
||||||
protected static HSSFWorkbook workbook = null;
|
|
||||||
|
|
||||||
static {
|
|
||||||
try {
|
|
||||||
FileInputStream fin = new FileInputStream( FILENAME );
|
|
||||||
workbook = new HSSFWorkbook( fin );
|
|
||||||
fin.close();
|
|
||||||
}
|
|
||||||
catch (Exception e) {e.printStackTrace();}
|
|
||||||
}
|
|
||||||
protected CellReference beginCell;
|
protected CellReference beginCell;
|
||||||
protected int getBeginRow() {
|
protected int getBeginRow() {
|
||||||
return beginCell.getRow();
|
return beginCell.getRow();
|
||||||
@ -98,11 +90,14 @@ public class GenericFormulaTestCase extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public GenericFormulaTestCase(String beginCell) {
|
public GenericFormulaTestCase(String beginCell) {
|
||||||
super("genericTest");
|
super("genericTest");
|
||||||
this.beginCell = new CellReference(beginCell);
|
this.beginCell = new CellReference(beginCell);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUp() {
|
public void setUp() throws Exception {
|
||||||
|
FileInputStream fin = new FileInputStream( FILENAME );
|
||||||
|
workbook = new HSSFWorkbook( fin );
|
||||||
|
fin.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void genericTest() throws Exception {
|
public void genericTest() throws Exception {
|
||||||
|
Loading…
Reference in New Issue
Block a user