package org.apache.poi.hssf.record.formula;
import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.BitField;
+
+import org.apache.poi.hssf.util.ReferenceUtil;
/**
* Specifies a rectangular area of cells
private short field_2_last_row;
private short field_3_first_column;
private short field_4_last_column;
+
+ private BitField rowRelative = new BitField(0x8000);
+ private BitField colRelative = new BitField(0x4000);
+ private BitField column = new BitField(0x3FFF);
+
/** Creates new AreaPtg */
public AreaPtg()
{
}
+
+ public AreaPtg(String arearef) {
+ int[] xyxy = ReferenceUtil.getXYXYFromAreaRef(arearef);
+ setFirstRow((short)xyxy[0]);
+ setFirstColumn((short)xyxy[1]);
+ setLastRow((short)xyxy[2]);
+ setLastColumn((short)xyxy[3]);
+
+ }
public AreaPtg(byte [] data, int offset)
{
buffer.append("firstCol = " + getFirstColumn()).append("\n");
buffer.append("lastCol = " + getLastColumn()).append("\n");
buffer.append("firstColRowRel= "
- + isFirstColRowRelative()).append("\n");
+ + 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();
}
- public void writeBytes(byte [] array, int offset)
- {
+ public void writeBytes(byte [] array, int offset) {
+ array[offset] = sid;
+ LittleEndian.putShort(array,offset+1,field_1_first_row);
+ LittleEndian.putShort(array,offset+3,field_2_last_row);
+ LittleEndian.putShort(array,offset+5,field_3_first_column);
+ LittleEndian.putShort(array,offset+7,field_4_last_column);
}
public int getSize()
public short getFirstColumn()
{
- return ( short ) (field_3_first_column & 0x3FFF);
+ return column.getShortValue(field_3_first_column);
}
public short getFirstColumnRaw()
return field_3_first_column;
}
- public boolean isFirstColRowRelative()
+ public boolean isFirstRowRelative()
{
- return (((getFirstColumnRaw()) & 0x8000) == 0x8000);
+ return rowRelative.isSet(field_3_first_column);
+ }
+
+ public void setFirstRowRelative(boolean rel) {
+ field_3_first_column=rowRelative.setShortBoolean(field_3_first_column,rel);
}
public boolean isFirstColRelative()
{
- return (((getFirstColumnRaw()) & 0x4000) == 0x4000);
+ return colRelative.isSet(field_3_first_column);
+ }
+
+ public void setFirstColRelative(boolean rel) {
+ field_3_first_column=colRelative.setShortBoolean(field_3_first_column,rel);
}
+
public void setFirstColumn(short column)
{
field_3_first_column = column; // fixme
public short getLastColumn()
{
- return ( short ) (field_4_last_column & 0x3FFF); // fixme
+ return column.getShortValue(field_4_last_column);
}
public short getLastColumnRaw()
return field_4_last_column;
}
- public boolean isLastColRowRelative()
+ public boolean isLastRowRelative()
{
- return (((getLastColumnRaw()) & 0x8000) == 1);
+ return rowRelative.isSet(field_4_last_column);
+ }
+
+ public void setLastRowRelative(boolean rel) {
+ field_4_last_column=rowRelative.setShortBoolean(field_4_last_column,rel);
}
public boolean isLastColRelative()
{
- return (((getFirstColumnRaw()) & 0x4000) == 1);
+ return colRelative.isSet(field_4_last_column);
+ }
+
+ public void setLastColRelative(boolean rel) {
+ field_4_last_column=colRelative.setShortBoolean(field_4_last_column,rel);
}
+
public void setLastColumn(short column)
{
{
String firstrow = "" + (getFirstRow() + 1);
String lastrow = null;
-
- if (isLastColRowRelative())
- {
- lastrow = "" + (getFirstRow() + getLastRow());
- }
- else
- {
- lastrow = "" + (getLastRow() + 1);
- }
-
// String firstcol = ""+
// String lastcol
- return colNumToLetter(getFirstColumn()) + firstrow + ":"
- + colNumToLetter(getLastColumn()) + lastrow;
+ return ReferenceUtil.getReferenceFromXY(getFirstRow(),getFirstColumn()) + ":"
+ + ReferenceUtil.getReferenceFromXY(getLastRow(),getLastColumn());
}
- public String colNumToLetter(int col)
- {
- byte[] b =
- {
- 0x41
- };
-
- b[ 0 ] += ( byte ) col;
- String retval = null;
-
- try
- {
- retval = new String(b, "UTF-8");
- }
- catch (java.io.UnsupportedEncodingException e)
- {
- throw new RuntimeException(
- "NON JDK 1.3 COMPLIANT JVM -- YOUR JVM MUST SUPPORT UTF-8 encoding as per docs!");
- }
- return retval;
- }
}
+++ /dev/null
-/*
- * DummyFunctionPtg.java
- *
- *
- */
-
-
-package org.apache.poi.hssf.record.formula;
-
-import java.util.List;
-/**
- * DUMMY DUMMY DUMMY
- * This class exists only becoz i dont know how to handle functions in formula's properly
- * to be used only for testing my parser.
- * @author aviks
- * @version
- */
-public class DummyFunctionPtg extends OperationPtg {
- private String name;
- private int numOperands;
- /** Creates new DummyFunctionPtg */
- public DummyFunctionPtg() {
- }
-
- public DummyFunctionPtg(String pName,int pNumOperands) {
- name=pName;
- numOperands = pNumOperands;
- }
-
- public int getType() {
- return -1;
- }
-
- public int getNumberOfOperands() {
- return numOperands;
- }
- public String getName() {
- return name;
- }
-
- public String toFormulaString() {
- return getName()+getNumberOfOperands();
- }
-
- public String toFormulaString(Ptg[] operands) {
- StringBuffer buf = new StringBuffer();
- buf.append(getName()+"(");
- for (int i=0;i<operands.length;i++) {
- buf.append(operands[i].toFormulaString());
- }
- buf.append(")");
- return buf.toString();
- }
-
- public String toFormulaString(String[] operands) {
- StringBuffer buf = new StringBuffer();
- buf.append(getName()+"(");
- if (operands.length >0) {
- for (int i=0;i<operands.length;i++) {
- buf.append(operands[i]);
- buf.append(',');
- }
- buf.deleteCharAt(buf.length()-1);
- }
- buf.append(")");
- return buf.toString();
- }
-
-
- public void writeBytes(byte[] array, int offset) {
- }
-
- public int getSize() {
- return 0;
- }
-
- public void manipulate(List source, List results, int pos) {
- }
-
-}
--- /dev/null
+/*
+ * DummyFunctionPtg.java
+ *
+ *
+ */
+
+
+package org.apache.poi.hssf.record.formula;
+
+import java.util.List;
+/**
+ * DUMMY DUMMY DUMMY
+ * This class exists only becoz i dont know how to handle functions in formula's properly
+ * to be used only for testing my parser.
+ * @author aviks
+ * @version
+ */
+public class FunctionPtg extends OperationPtg {
+ private String name;
+ private int numOperands;
+ /** Creates new DummyFunctionPtg */
+ public FunctionPtg() {
+ }
+
+ public FunctionPtg(String pName, int pNumOperands) {
+ name=pName;
+ numOperands = pNumOperands;
+ }
+
+ public int getType() {
+ return -1;
+ }
+
+ public int getNumberOfOperands() {
+ return numOperands;
+ }
+ public String getName() {
+ return name;
+ }
+
+ public String toFormulaString() {
+ return getName()+getNumberOfOperands();
+ }
+
+ public String toFormulaString(Ptg[] operands) {
+ StringBuffer buf = new StringBuffer();
+ buf.append(getName()+"(");
+ for (int i=0;i<operands.length;i++) {
+ buf.append(operands[i].toFormulaString());
+ }
+ buf.append(")");
+ return buf.toString();
+ }
+
+ public String toFormulaString(String[] operands) {
+ StringBuffer buf = new StringBuffer();
+ buf.append(getName()+"(");
+ if (operands.length >0) {
+ for (int i=0;i<operands.length;i++) {
+ buf.append(operands[i]);
+ buf.append(',');
+ }
+ buf.deleteCharAt(buf.length()-1);
+ }
+ buf.append(")");
+ return buf.toString();
+ }
+
+
+ public void writeBytes(byte[] array, int offset) {
+ }
+
+ public int getSize() {
+ return 0;
+ }
+
+ public void manipulate(List source, List results, int pos) {
+ }
+
+}