improved toString and refactored toFormulaString on Area(3D)Ptg
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@658833 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
15db21d326
commit
b1ad25f7e3
@ -27,7 +27,7 @@ import org.apache.poi.util.LittleEndian;
|
||||
|
||||
|
||||
/**
|
||||
* Title: Area 3D Ptg - 3D referecnce (Sheet + Area)<P>
|
||||
* Title: Area 3D Ptg - 3D reference (Sheet + Area)<P>
|
||||
* Description: Defined a area in Extern Sheet. <P>
|
||||
* REFERENCE: <P>
|
||||
* @author Libin Roman (Vista Portal LDT. Developer)
|
||||
@ -35,7 +35,6 @@ import org.apache.poi.util.LittleEndian;
|
||||
* @author Jason Height (jheight at chariot dot net dot au)
|
||||
* @version 1.0-pre
|
||||
*/
|
||||
|
||||
public class Area3DPtg extends Ptg implements AreaI
|
||||
{
|
||||
public final static byte sid = 0x3b;
|
||||
@ -84,23 +83,15 @@ public class Area3DPtg extends Ptg implements AreaI
|
||||
setExternSheetIndex(externalSheetIndex);
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
|
||||
buffer.append( "AreaPtg\n" );
|
||||
buffer.append( "Index to Extern Sheet = " + getExternSheetIndex() ).append( "\n" );
|
||||
buffer.append( "firstRow = " + getFirstRow() ).append( "\n" );
|
||||
buffer.append( "lastRow = " + getLastRow() ).append( "\n" );
|
||||
buffer.append( "firstCol = " + getFirstColumn() ).append( "\n" );
|
||||
buffer.append( "lastCol = " + getLastColumn() ).append( "\n" );
|
||||
buffer.append( "firstColRel= "
|
||||
+ isFirstRowRelative() ).append( "\n" );
|
||||
buffer.append( "lastColRowRel = "
|
||||
+ isLastRowRelative() ).append( "\n" );
|
||||
buffer.append( "firstColRel = " + isFirstColRelative() ).append( "\n" );
|
||||
buffer.append( "lastColRel = " + isLastColRelative() ).append( "\n" );
|
||||
return buffer.toString();
|
||||
public String toString() {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append(getClass().getName());
|
||||
sb.append(" [");
|
||||
sb.append("sheetIx=").append(getExternSheetIndex());
|
||||
sb.append(" ! ");
|
||||
sb.append(AreaReference.formatAsString(this));
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public void writeBytes( byte[] array, int offset )
|
||||
@ -284,7 +275,7 @@ public class Area3DPtg extends Ptg implements AreaI
|
||||
}
|
||||
|
||||
// Now the normal area bit
|
||||
retval.append( AreaPtg.toFormulaString(this, book) );
|
||||
retval.append(AreaReference.formatAsString(this));
|
||||
|
||||
// All done
|
||||
return retval.toString();
|
||||
@ -326,6 +317,7 @@ public class Area3DPtg extends Ptg implements AreaI
|
||||
|
||||
public int hashCode()
|
||||
{
|
||||
// TODO - hashCode seems to be unused
|
||||
int result;
|
||||
result = (int) field_1_index_extern_sheet;
|
||||
result = 29 * result + (int) field_2_first_row;
|
||||
|
@ -114,23 +114,13 @@ public class AreaPtg extends Ptg implements AreaI {
|
||||
return "AreaPtg";
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
|
||||
buffer.append(getAreaPtgName());
|
||||
buffer.append("\n");
|
||||
buffer.append("firstRow = " + getFirstRow()).append("\n");
|
||||
buffer.append("lastRow = " + getLastRow()).append("\n");
|
||||
buffer.append("firstCol = " + getFirstColumn()).append("\n");
|
||||
buffer.append("lastCol = " + getLastColumn()).append("\n");
|
||||
buffer.append("firstColRowRel= "
|
||||
+ isFirstRowRelative()).append("\n");
|
||||
buffer.append("lastColRowRel = "
|
||||
+ isLastRowRelative()).append("\n");
|
||||
buffer.append("firstColRel = " + isFirstColRelative()).append("\n");
|
||||
buffer.append("lastColRel = " + isLastColRelative()).append("\n");
|
||||
return buffer.toString();
|
||||
public String toString() {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append(getClass().getName());
|
||||
sb.append(" [");
|
||||
sb.append(AreaReference.formatAsString(this));
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public void writeBytes(byte [] array, int offset) {
|
||||
@ -307,19 +297,8 @@ public class AreaPtg extends Ptg implements AreaI {
|
||||
field_4_last_column = column;
|
||||
}
|
||||
|
||||
public String toFormulaString(HSSFWorkbook book)
|
||||
{
|
||||
return toFormulaString(this, book);
|
||||
}
|
||||
protected static String toFormulaString(AreaI area, HSSFWorkbook book) {
|
||||
CellReference topLeft = new CellReference(area.getFirstRow(),area.getFirstColumn(),!area.isFirstRowRelative(),!area.isFirstColRelative());
|
||||
CellReference botRight = new CellReference(area.getLastRow(),area.getLastColumn(),!area.isLastRowRelative(),!area.isLastColRelative());
|
||||
|
||||
if(AreaReference.isWholeColumnReference(topLeft, botRight)) {
|
||||
return (new AreaReference(topLeft, botRight)).formatAsString();
|
||||
} else {
|
||||
return topLeft.formatAsString() + ":" + botRight.formatAsString();
|
||||
}
|
||||
public String toFormulaString(HSSFWorkbook book) {
|
||||
return AreaReference.formatAsString(this);
|
||||
}
|
||||
|
||||
public byte getDefaultOperandClass() {
|
||||
|
@ -15,12 +15,13 @@
|
||||
limitations under the License.
|
||||
==================================================================== */
|
||||
|
||||
|
||||
package org.apache.poi.hssf.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import org.apache.poi.hssf.record.formula.AreaI;
|
||||
|
||||
public final class AreaReference {
|
||||
|
||||
/** The character (!) that separates sheet names from cell references */
|
||||
@ -210,6 +211,18 @@ public final class AreaReference {
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
/**
|
||||
* Formats a 2-D area as it would appear in a formula. See formatAsString() (no-arg)
|
||||
*/
|
||||
public static String formatAsString(AreaI area) {
|
||||
CellReference topLeft = new CellReference(area.getFirstRow(),area.getFirstColumn(),!area.isFirstRowRelative(),!area.isFirstColRelative());
|
||||
CellReference botRight = new CellReference(area.getLastRow(),area.getLastColumn(),!area.isLastRowRelative(),!area.isLastColRelative());
|
||||
|
||||
if(isWholeColumnReference(topLeft, botRight)) {
|
||||
return (new AreaReference(topLeft, botRight)).formatAsString();
|
||||
}
|
||||
return topLeft.formatAsString() + ":" + botRight.formatAsString();
|
||||
}
|
||||
public String toString() {
|
||||
StringBuffer sb = new StringBuffer(64);
|
||||
sb.append(getClass().getName()).append(" [");
|
||||
|
Loading…
Reference in New Issue
Block a user