mirror of https://github.com/apache/poi.git
committing patches supplied by Matthew McClain for bug 8757. This will handle most cases, since majority formulas expect value class params. Ptgs to be refactored for full functionality
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@352600 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
691e0bb9cc
commit
fe3a314fe4
|
@ -155,20 +155,23 @@ public abstract class Ptg
|
|||
}
|
||||
return result;
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
public static Ptg createPtg(byte [] data, int offset)
|
||||
{
|
||||
byte id = data[ offset + 0 ];
|
||||
Ptg retval = null;
|
||||
|
||||
final int valueRef = ReferencePtg.sid + 0x20; //note this only matters for READ
|
||||
final int arrayRef = ReferencePtg.sid + 0x40; // excel doesn't really care which one you
|
||||
// write.
|
||||
final int refRef = ReferencePtg.sid - 0x20;
|
||||
final int arrayRef = ReferencePtg.sid + 0x20;
|
||||
|
||||
|
||||
final int valueFunc = FunctionPtg.sid + 0x20; //note this only matters for READ
|
||||
final int arrayFunc = FunctionPtg.sid + 0x40; // excel doesn't really care which one you
|
||||
// write.
|
||||
final int valueFunc = FunctionPtg.sid + 0x20;
|
||||
final int arrayFunc = FunctionPtg.sid + 0x40;
|
||||
|
||||
|
||||
final int refArea = AreaPtg.sid-0x20;
|
||||
final int arrayArea = AreaPtg.sid+0x20;
|
||||
|
||||
|
||||
switch (id)
|
||||
|
@ -219,7 +222,7 @@ public abstract class Ptg
|
|||
retval = new ReferencePtg(data, offset);
|
||||
break;
|
||||
|
||||
case valueRef :
|
||||
case refRef :
|
||||
retval = new ReferencePtg(data, offset);
|
||||
break;
|
||||
|
||||
|
|
|
@ -76,7 +76,8 @@ import org.apache.poi.hssf.util.CellReference;
|
|||
public class ReferencePtg extends Ptg
|
||||
{
|
||||
private final static int SIZE = 5;
|
||||
public final static byte sid = 0x24;
|
||||
//public final static byte sid = 0x24;
|
||||
public final static byte sid = 0x44;
|
||||
private short field_1_row;
|
||||
private short field_2_col;
|
||||
private BitField rowRelative = new BitField(0x8000);
|
||||
|
|
|
@ -723,9 +723,9 @@ extends TestCase {
|
|||
c.setCellFormula("A$3+A$2");
|
||||
c=r.createCell( (short) 3);
|
||||
c.setCellFormula("$A$3+$A$2");
|
||||
c=r.createCell( (short) 4);
|
||||
c=r.createCell( (short) 4);
|
||||
c.setCellFormula("SUM($A$3,$A$2)");
|
||||
|
||||
|
||||
wb.write(out);
|
||||
out.close();
|
||||
assertTrue("file exists",file.exists());
|
||||
|
@ -742,10 +742,40 @@ extends TestCase {
|
|||
assertTrue("A$3+A$2", ("A$3+A$2").equals(c.getCellFormula()));
|
||||
c = r.getCell((short)3);
|
||||
assertTrue("$A$3+$A$2", ("$A$3+$A$2").equals(c.getCellFormula()));
|
||||
c = r.getCell((short)4);
|
||||
c = r.getCell((short)4);
|
||||
assertTrue("SUM($A$3,$A$2)", ("SUM($A$3,$A$2)").equals(c.getCellFormula()));
|
||||
in.close();
|
||||
}
|
||||
|
||||
public void testRVAoperands() throws Exception {
|
||||
File file = File.createTempFile("testFormulaRVA",".xls");
|
||||
FileOutputStream out = new FileOutputStream(file);
|
||||
HSSFWorkbook wb = new HSSFWorkbook();
|
||||
HSSFSheet s = wb.createSheet();
|
||||
HSSFRow r = null;
|
||||
HSSFCell c = null;
|
||||
|
||||
|
||||
r = s.createRow((short) 0);
|
||||
|
||||
c = r.createCell((short) 0);
|
||||
c.setCellFormula("A3+A2");
|
||||
c=r.createCell( (short) 1);
|
||||
c.setCellFormula("AVERAGE(A3,A2)");
|
||||
c=r.createCell( (short) 2);
|
||||
c.setCellFormula("ROW(A3)");
|
||||
c=r.createCell( (short) 3);
|
||||
c.setCellFormula("AVERAGE(A2:A3)");
|
||||
c=r.createCell( (short) 4);
|
||||
c.setCellFormula("POWER(A2,A3)");
|
||||
|
||||
r = s.createRow((short) 1);c=r.createCell( (short) 0); c.setCellValue(2.0);
|
||||
r = s.createRow((short) 2);c=r.createCell( (short) 0); c.setCellValue(3.0);
|
||||
|
||||
wb.write(out);
|
||||
out.close();
|
||||
assertTrue("file exists",file.exists());
|
||||
}
|
||||
public static void main(String [] args) {
|
||||
System.out
|
||||
.println("Testing org.apache.poi.hssf.usermodel.TestFormulas");
|
||||
|
|
Loading…
Reference in New Issue