import org.apache.poi.util.LittleEndian;
import org.apache.poi.hssf.util.RangeAddress;
import org.apache.poi.hssf.util.AreaReference;
+import org.apache.poi.hssf.util.CellReference;
+
+import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.util.BitField;
/**
* Title: Area 3D Ptg - 3D referecnce (Sheet + Area)<P>
* Description: Defined a area in Extern Sheet. <P>
* REFERENCE: <P>
* @author Libin Roman (Vista Portal LDT. Developer)
+ * @author avik
* @version 1.0-pre
*/
private short field_3_last_row;
private short field_4_first_column;
private short field_5_last_column;
+
+ private BitField rowRelative = new BitField(0x8000);
+ private BitField colRelative = new BitField(0x4000);
/** Creates new AreaPtg */
public Area3DPtg() {}
setFirstColumn((short)ar.getCells()[0].getCol());
setLastRow((short)ar.getCells()[1].getRow());
setLastColumn((short)ar.getCells()[1].getCol());
- //setFirstColRelative(!ar.getCells()[0].isColAbsolute());
- //setLastColRelative(!ar.getCells()[1].isColAbsolute());
- //setFirstRowRelative(!ar.getCells()[0].isRowAbsolute());
- //setLastRowRelative(!ar.getCells()[1].isRowAbsolute());
+ setFirstColRelative(!ar.getCells()[0].isColAbsolute());
+ setLastColRelative(!ar.getCells()[1].isColAbsolute());
+ setFirstRowRelative(!ar.getCells()[0].isRowAbsolute());
+ setLastRowRelative(!ar.getCells()[1].isRowAbsolute());
setExternSheetIndex(externIdx);
}
buffer.append("lastRow = " + getLastRow()).append("\n");
buffer.append("firstCol = " + getFirstColumn()).append("\n");
buffer.append("lastCol = " + getLastColumn()).append("\n");
- buffer.append("firstColRowRel= "
- + isFirstColRowRelative()).append("\n");
+ buffer.append("firstColRel= "
+ + isFirstRowRelative()).append("\n");
buffer.append("lastColRowRel = "
- + isLastColRowRelative()).append("\n");
+ + isLastRowRelative()).append("\n");
buffer.append("firstColRel = " + isFirstColRelative()).append("\n");
buffer.append("lastColRel = " + isLastColRelative()).append("\n");
return buffer.toString();
return field_4_first_column;
}
- public boolean isFirstColRowRelative()
+ public boolean isFirstRowRelative()
{
- return (((getFirstColumnRaw()) & 0x8000) == 0x8000);
+ return rowRelative.isSet(field_4_first_column);
}
-
+
public boolean isFirstColRelative()
{
- return (((getFirstColumnRaw()) & 0x4000) == 0x4000);
+ return colRelative.isSet(field_4_first_column);
}
public void setFirstColumn(short column)
return field_5_last_column;
}
- public boolean isLastColRowRelative()
+ public boolean isLastRowRelative()
{
- return (((getLastColumnRaw()) & 0x8000) == 1);
+ return rowRelative.isSet(field_5_last_column);
}
-
public boolean isLastColRelative()
{
- return (((getFirstColumnRaw()) & 0x4000) == 1);
+ return colRelative.isSet(field_5_last_column);
}
-
+
public void setLastColumn(short column)
{
field_5_last_column &= 0xFF00;
{
field_5_last_column = column;
}
+
+ /**
+ * sets the first row to relative or not
+ * @param isRelative or not.
+ */
+ public void setFirstRowRelative(boolean rel) {
+ field_4_first_column=rowRelative.setShortBoolean(field_4_first_column,rel);
+ }
+
+ /**
+ * set whether the first column is relative
+ */
+ public void setFirstColRelative(boolean rel) {
+ field_4_first_column=colRelative.setShortBoolean(field_4_first_column,rel);
+ }
+
+ /**
+ * set whether the last row is relative or not
+ * @param last row relative
+ */
+ public void setLastRowRelative(boolean rel) {
+ field_5_last_column=rowRelative.setShortBoolean(field_5_last_column,rel);
+ }
+
+ /**
+ * set whether the last column should be relative or not
+ */
+ public void setLastColRelative(boolean rel) {
+ field_5_last_column=colRelative.setShortBoolean(field_5_last_column,rel);
+ }
+
public String getArea(){
RangeAddress ra = new RangeAddress( getFirstColumn(),getFirstRow() + 1, getLastColumn(), getLastRow() + 1);
public String toFormulaString()
{
- String result = getArea();
-
- return result;
+ StringBuffer retval = new StringBuffer();
+ Object book = Workbook.currentBook.get();
+ if (book != null) {
+ retval.append(((Workbook) book).findSheetNameFromExternSheet(this.field_1_index_extern_sheet));
+ retval.append('!');
+ }
+ retval.append((new CellReference(getFirstRow(),getFirstColumn(),!isFirstRowRelative(),!isFirstColRelative())).toString());
+ retval.append(':');
+ retval.append((new CellReference(getLastRow(),getLastColumn(),!isLastRowRelative(),!isLastColRelative())).toString());
+ return retval.toString();
}
public byte getDefaultOperandClass() {
- return Ptg.CLASS_VALUE;
+ return Ptg.CLASS_REF;
}
}
import org.apache.poi.util.LittleEndian;
import org.apache.poi.hssf.util.RangeAddress;
import org.apache.poi.hssf.util.CellReference;
+import org.apache.poi.util.BitField;
+import org.apache.poi.hssf.model.Workbook;
+
/**
* Title: Reference 3D Ptg <P>
* Description: Defined a cell in extern sheet. <P>
private short field_1_index_extern_sheet;
private short field_2_row;
private short field_3_column;
+ private BitField rowRelative = new BitField(0x8000);
+ private BitField colRelative = new BitField(0x4000);
/** Creates new AreaPtg */
public Ref3DPtg() {}
CellReference c= new CellReference(cellref);
setRow((short) c.getRow());
setColumn((short) c.getCol());
- //setColRelative(!c.isColAbsolute());
- //setRowRelative(!c.isRowAbsolute());
+ setColRelative(!c.isColAbsolute());
+ setRowRelative(!c.isRowAbsolute());
setExternSheetIndex(externIdx);
}
buffer.append("Row = " + getRow()).append("\n");
buffer.append("Col = " + getColumn()).append("\n");
buffer.append("ColRowRel= "
- + isColRowRelative()).append("\n");
+ + isRowRelative()).append("\n");
buffer.append("ColRel = " + isColRelative()).append("\n");
return buffer.toString();
}
return field_3_column;
}
- public boolean isColRowRelative() {
- return (((getColumnRaw()) & 0x8000) == 0x8000);
+ public boolean isRowRelative()
+ {
+ return rowRelative.isSet(field_3_column);
}
-
- public boolean isColRelative() {
- return (((getColumnRaw()) & 0x4000) == 0x4000);
+
+ public void setRowRelative(boolean rel) {
+ field_3_column=rowRelative.setShortBoolean(field_3_column,rel);
+ }
+
+ public boolean isColRelative()
+ {
+ return colRelative.isSet(field_3_column);
+ }
+
+ public void setColRelative(boolean rel) {
+ field_3_column=colRelative.setShortBoolean(field_3_column,rel);
}
-
public void setColumn(short column) {
field_3_column &= 0xFF00;
field_3_column |= column & 0xFF;
}
public String toFormulaString() {
- String result = getArea();
-
- return result;
+ StringBuffer retval = new StringBuffer();
+ Object book = Workbook.currentBook.get();
+ if (book != null) {
+ retval.append(((Workbook) book).findSheetNameFromExternSheet(this.field_1_index_extern_sheet));
+ retval.append('!');
+ }
+ retval.append((new CellReference(getRow(),getColumn(),!isRowRelative(),!isColRelative())).toString());
+ return retval.toString();
}
- public byte getDefaultOperandClass() {return Ptg.CLASS_VALUE;}
+ public byte getDefaultOperandClass() {return Ptg.CLASS_REF;}
}
{
String filename = System.getProperty("HSSF.testdata.path");
- File file = File.createTempFile("testSheetFormula",".xls");
+ File file = File.createTempFile("testSheetFormula",".xls");
FileOutputStream out = new FileOutputStream(file);
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet s = wb.createSheet("A");
r = s.createRow((short)0);
c=r.createCell((short)0); c.setCellFormula("AVERAGE(A!A1:B1)");
c=r.createCell((short)1); c.setCellFormula("A!A1+A!B1");
- c=r.createCell((short)2); c.setCellFormula("C!A1+C!B1");
+ c=r.createCell((short)2); c.setCellFormula("A!$A$1+A!$B1");
wb.write(out);
out.close();
s = wb.getSheet("B");
r = s.getRow(0);
c = r.getCell((short)0);
- //assertTrue("expected: AVERAGE(A!A1:B1) got: "+c.getCellFormula(), ("AVERAGE(A!A1:B1)").equals(c.getCellFormula()));
+ assertTrue("expected: AVERAGE(A!A1:B1) got: "+c.getCellFormula(), ("AVERAGE(A!A1:B1)").equals(c.getCellFormula()));
c = r.getCell((short)1);
- //assertTrue("expected: A!A1+A!B1 got: "+c.getCellFormula(), ("A!A1+A!B1").equals(c.getCellFormula()));
+ assertTrue("expected: A!A1+A!B1 got: "+c.getCellFormula(), ("A!A1+A!B1").equals(c.getCellFormula()));
in.close();
}