View | Details | Raw Unified | Return to bug 19888
Collapse All | Expand All

(-)src/java/org/apache/poi/hssf/util/AreaReference.java (-10 / +19 lines)
Lines 55-62 Link Here
55
package org.apache.poi.hssf.util;
55
package org.apache.poi.hssf.util;
56
56
57
public class AreaReference {
57
public class AreaReference {
58
    
58
59
    
59
60
private CellReference [] cells;
60
private CellReference [] cells;
61
private int dim;
61
private int dim;
62
62
Lines 80-86 Link Here
80
    public CellReference[] getCells() {
80
    public CellReference[] getCells() {
81
        return cells;
81
        return cells;
82
    }
82
    }
83
    
83
84
    public String toString() {
84
    public String toString() {
85
        StringBuffer retval = new StringBuffer();
85
        StringBuffer retval = new StringBuffer();
86
        for (int i=0;i<dim;i++){
86
        for (int i=0;i<dim;i++){
Lines 90-108 Link Here
90
        retval.deleteCharAt(0);
90
        retval.deleteCharAt(0);
91
        return retval.toString();
91
        return retval.toString();
92
    }
92
    }
93
    
93
94
    /**
94
    /**
95
     * seperates Area refs in two parts and returns them as seperate elements in a 
95
     * seperates Area refs in two parts and returns them as seperate elements in a
96
     * String array
96
     * String array
97
     */
97
     */
98
    private String[] seperateAreaRefs(String reference) {
98
    private String[] seperateAreaRefs(String reference) {
99
        String retval[] = new String[2];
99
        String[] retval = null;
100
100
        int length = reference.length();
101
        int length = reference.length();
101
        
102
102
        int loc = reference.indexOf(':',0);
103
        int loc = reference.indexOf(':',0);
103
        
104
        if(loc == -1){
104
        retval[0] = reference.substring(0,loc);
105
           retval = new String[1];
105
        retval[1] = reference.substring(loc+1);        
106
           retval[0] = reference;
107
        }
108
        else{
109
           retval = new String[2];
110
           int sheetStart = reference.indexOf("!");
111
112
           retval[0] = reference.substring(0, sheetStart+1) + reference.substring(sheetStart + 1,loc);
113
           retval[1] = reference.substring(0, sheetStart+1) + reference.substring(loc+1);
114
        }
106
        return retval;
115
        return retval;
107
    }
116
    }
108
}
117
}
(-)src/java/org/apache/poi/hssf/util/CellReference.java (-30 / +35 lines)
Lines 60-104 Link Here
60
 * @author  Dennis Doubleday (patch to seperateRowColumns())
60
 * @author  Dennis Doubleday (patch to seperateRowColumns())
61
 */
61
 */
62
public class CellReference {
62
public class CellReference {
63
    
63
64
    /** Creates new CellReference */
64
    /** Creates new CellReference */
65
    private int row;
65
    private int row;
66
    private int col;
66
    private int col;
67
    private String sheetName;
67
    private boolean rowAbs;
68
    private boolean rowAbs;
68
    private boolean colAbs;
69
    private boolean colAbs;
69
    
70
70
    public CellReference(String cellRef) {
71
    public CellReference(String cellRef) {
71
        String[] parts = seperateRowColumns(cellRef);
72
        String[] parts = separateRefParts(cellRef);
72
        String ref = parts[0];
73
        sheetName = parts[0];
74
        String ref = parts[1];
73
        if (ref.charAt(0) == '$') {
75
        if (ref.charAt(0) == '$') {
74
            colAbs=true; 
76
            colAbs=true;
75
            ref=ref.substring(1);
77
            ref=ref.substring(1);
76
        }
78
        }
77
        col = convertColStringToNum(ref);
79
        col = convertColStringToNum(ref);
78
        ref=parts[1];
80
        ref=parts[2];
79
        if (ref.charAt(0) == '$') {
81
        if (ref.charAt(0) == '$') {
80
            rowAbs=true; 
82
            rowAbs=true;
81
            ref=ref.substring(1);
83
            ref=ref.substring(1);
82
        }
84
        }
83
        row = Integer.parseInt(ref)-1;
85
        row = Integer.parseInt(ref)-1;
84
    }
86
    }
85
    
87
86
    public CellReference(int pRow, int pCol) {
88
    public CellReference(int pRow, int pCol) {
87
        this(pRow,pCol,false,false);
89
        this(pRow,pCol,false,false);
88
    }
90
    }
89
    
91
90
    public CellReference(int pRow, int pCol, boolean pAbsRow, boolean pAbsCol) {
92
    public CellReference(int pRow, int pCol, boolean pAbsRow, boolean pAbsCol) {
91
        row=pRow;col=pCol;
93
        row=pRow;col=pCol;
92
        rowAbs = pAbsRow;
94
        rowAbs = pAbsRow;
93
        colAbs=pAbsCol;
95
        colAbs=pAbsCol;
94
        
96
95
    }
97
    }
96
    
98
97
    public int getRow(){return row;}
99
    public int getRow(){return row;}
98
    public int getCol(){return col;}
100
    public short getCol(){return (short) col;}
99
    public boolean isRowAbsolute(){return rowAbs;}
101
    public boolean isRowAbsolute(){return rowAbs;}
100
    public boolean isColAbsolute(){return colAbs;}
102
    public boolean isColAbsolute(){return colAbs;}
101
    
103
    public String getSheetName(){return sheetName;}
104
102
    /**
105
    /**
103
     * takes in a column reference portion of a CellRef and converts it from
106
     * takes in a column reference portion of a CellRef and converts it from
104
     * ALPHA-26 number format to 0-based base 10.
107
     * ALPHA-26 number format to 0-based base 10.
Lines 107-113 Link Here
107
        int len = ref.length();
110
        int len = ref.length();
108
        int retval=0;
111
        int retval=0;
109
        int pos = 0;
112
        int pos = 0;
110
        
113
111
        for (int k = ref.length()-1; k > -1; k--) {
114
        for (int k = ref.length()-1; k > -1; k--) {
112
            char thechar = ref.charAt(k);
115
            char thechar = ref.charAt(k);
113
            if ( pos == 0) {
116
            if ( pos == 0) {
Lines 119-139 Link Here
119
        }
122
        }
120
        return retval-1;
123
        return retval-1;
121
    }
124
    }
122
    
125
123
    
126
124
    /**
127
    /**
125
     * Seperates the row from the columns and returns an array.  Element in
128
     * Seperates the row from the columns and returns an array.  Element in
126
     * position one is the substring containing the columns still in ALPHA-26
129
     * position one is the substring containing the columns still in ALPHA-26
127
     * number format.
130
     * number format.
128
     */
131
     */
129
    private String[] seperateRowColumns(String reference) {
132
    private String[] separateRefParts(String reference) {
130
        
133
131
        // Look for end of sheet name. This will either set
134
        // Look for end of sheet name. This will either set
132
        // start to 0 (if no sheet name present) or the
135
        // start to 0 (if no sheet name present) or the
133
        // index after the sheet reference ends.
136
        // index after the sheet reference ends.
134
        int start = reference.indexOf("!") + 1;
137
        String retval[] = new String[3];
138
139
        int start = reference.indexOf("!");
140
        if (start != -1) retval[0] = reference.substring(0, start);
141
        start += 1;
135
142
136
        String retval[] = new String[2];
137
        int length = reference.length();
143
        int length = reference.length();
138
144
139
145
Lines 145-157 Link Here
145
                break;
151
                break;
146
            }
152
            }
147
        }
153
        }
148
        
154
149
        
155
        retval[1] = reference.substring(start,loc);
150
        retval[0] = reference.substring(start,loc);
156
        retval[2] = reference.substring(loc);
151
        retval[1] = reference.substring(loc);
152
        return retval;
157
        return retval;
153
    }
158
    }
154
    
159
155
    /**
160
    /**
156
     * takes in a 0-based base-10 column and returns a ALPHA-26 representation
161
     * takes in a 0-based base-10 column and returns a ALPHA-26 representation
157
     */
162
     */
Lines 161-184 Link Here
161
        int div = col / 26;
166
        int div = col / 26;
162
        char small=(char)(mod + 65);
167
        char small=(char)(mod + 65);
163
        char big = (char)(div + 64);
168
        char big = (char)(div + 64);
164
        
169
165
        if (div == 0) {
170
        if (div == 0) {
166
            retval = ""+small;
171
            retval = ""+small;
167
        } else {
172
        } else {
168
            retval = ""+big+""+small;
173
            retval = ""+big+""+small;
169
        }
174
        }
170
        
175
171
        return retval;
176
        return retval;
172
    }
177
    }
173
    
178
174
    
179
175
    public String toString() {
180
    public String toString() {
176
        StringBuffer retval = new StringBuffer();
181
        StringBuffer retval = new StringBuffer();
177
        retval.append( (colAbs)?"$":"");
182
        retval.append( (colAbs)?"$":"");
178
        retval.append( convertNumToColString(col));
183
        retval.append( convertNumToColString(col));
179
        retval.append((rowAbs)?"$":"");
184
        retval.append((rowAbs)?"$":"");
180
        retval.append(row+1);
185
        retval.append(row+1);
181
    
186
182
    return retval.toString();
187
    return retval.toString();
183
    }
188
    }
184
}
189
}

Return to bug 19888