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

(-)src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java (+287 lines)
Line 0 Link Here
1
/* ====================================================================
2
   Licensed to the Apache Software Foundation (ASF) under one or more
3
   contributor license agreements.  See the NOTICE file distributed with
4
   this work for additional information regarding copyright ownership.
5
   The ASF licenses this file to You under the Apache License, Version 2.0
6
   (the "License"); you may not use this file except in compliance with
7
   the License.  You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
==================================================================== */
17
18
package org.apache.poi.xssf.usermodel;
19
20
import org.apache.poi.ss.usermodel.CellStyle;
21
import org.apache.poi.ss.usermodel.Font;
22
import org.apache.poi.ss.usermodel.Workbook;
23
import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder;
24
import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder.BorderSides;
25
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder;
26
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTStylesheet;
27
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf;
28
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STBorderStyle.Enum;
29
30
31
public class XSSFCellStyle implements CellStyle {
32
	
33
	private CTStylesheet stylesheet;
34
	private CTXf cellXf;
35
	private CTXf cellStyleXf;
36
	private XSSFCellBorder cellBorder;
37
	
38
	public XSSFCellStyle(CTStylesheet stylesheet, int cellXfsId) {
39
		this.stylesheet = stylesheet;
40
		this.cellXf = stylesheet.getCellStyleXfs().getXfArray(cellXfsId);
41
		if (cellXf.isSetXfId()) {
42
			this.cellStyleXf = stylesheet.getCellStyleXfs().getXfArray((int) cellXf.getXfId());
43
		}
44
	}
45
46
	public short getAlignment() {
47
		// TODO Auto-generated method stub
48
		return 0;
49
	}
50
51
	public short getBorderBottom() {
52
		return (short) (getBorderStyle(BorderSides.BOTTOM).intValue() - 1);
53
	}
54
	
55
	public String getBorderBottomAsString() {
56
		return getBorderStyle(BorderSides.BOTTOM).toString();
57
	}
58
59
	public short getBorderLeft() {
60
		return (short) (getBorderStyle(BorderSides.LEFT).intValue() - 1);
61
	}
62
	
63
	public String getBorderLeftAsString() {
64
		return getBorderStyle(BorderSides.LEFT).toString();
65
	}
66
67
	public short getBorderRight() {
68
		return (short) (getBorderStyle(BorderSides.RIGHT).intValue() - 1);
69
	}
70
	
71
	public String getBorderRightAsString() {
72
		return getBorderStyle(BorderSides.RIGHT).toString();
73
	}
74
75
	public short getBorderTop() {
76
		return (short) (getBorderStyle(BorderSides.TOP).intValue() - 1);
77
	}
78
	
79
	public String getBorderTopAsString() {
80
		return getBorderStyle(BorderSides.TOP).toString();
81
	}
82
83
	public short getBottomBorderColor() {
84
		return getBorderColorBySide(BorderSides.BOTTOM);
85
	}
86
87
	public short getDataFormat() {
88
		// TODO Auto-generated method stub
89
		return 0;
90
	}
91
92
	public short getFillBackgroundColor() {
93
		// TODO Auto-generated method stub
94
		return 0;
95
	}
96
97
	public short getFillForegroundColor() {
98
		// TODO Auto-generated method stub
99
		return 0;
100
	}
101
102
	public short getFillPattern() {
103
		// TODO Auto-generated method stub
104
		return 0;
105
	}
106
107
	public Font getFont(Workbook parentWorkbook) {
108
		// TODO Auto-generated method stub
109
		return null;
110
	}
111
112
	public short getFontIndex() {
113
		// TODO Auto-generated method stub
114
		return 0;
115
	}
116
117
	public boolean getHidden() {
118
		// TODO Auto-generated method stub
119
		return false;
120
	}
121
122
	public short getIndention() {
123
		// TODO Auto-generated method stub
124
		return 0;
125
	}
126
127
	public short getIndex() {
128
		// TODO Auto-generated method stub
129
		return 0;
130
	}
131
132
	public short getLeftBorderColor() {
133
		return getBorderColorBySide(BorderSides.LEFT);
134
	}
135
136
	public boolean getLocked() {
137
		// TODO Auto-generated method stub
138
		return false;
139
	}
140
141
	public short getRightBorderColor() {
142
		return getBorderColorBySide(BorderSides.RIGHT);
143
	}
144
145
	public short getRotation() {
146
		// TODO Auto-generated method stub
147
		return 0;
148
	}
149
150
	public short getTopBorderColor() {
151
		return getBorderColorBySide(BorderSides.TOP);
152
	}
153
154
	public short getVerticalAlignment() {
155
		// TODO Auto-generated method stub
156
		return 0;
157
	}
158
159
	public boolean getWrapText() {
160
		// TODO Auto-generated method stub
161
		return false;
162
	}
163
164
	public void setAlignment(short align) {
165
		// TODO Auto-generated method stub
166
		
167
	}
168
169
	public void setBorderBottom(short border) {
170
		// TODO Auto-generated method stub
171
		
172
	}
173
174
	public void setBorderLeft(short border) {
175
		// TODO Auto-generated method stub
176
		
177
	}
178
179
	public void setBorderRight(short border) {
180
		// TODO Auto-generated method stub
181
		
182
	}
183
184
	public void setBorderTop(short border) {
185
		// TODO Auto-generated method stub
186
		
187
	}
188
189
	public void setBottomBorderColor(short color) {
190
		// TODO Auto-generated method stub
191
		
192
	}
193
194
	public void setDataFormat(short fmt) {
195
		// TODO Auto-generated method stub
196
		
197
	}
198
199
	public void setFillBackgroundColor(short bg) {
200
		// TODO Auto-generated method stub
201
		
202
	}
203
204
	public void setFillForegroundColor(short bg) {
205
		// TODO Auto-generated method stub
206
		
207
	}
208
209
	public void setFillPattern(short fp) {
210
		// TODO Auto-generated method stub
211
		
212
	}
213
214
	public void setFont(Font font) {
215
		// TODO Auto-generated method stub
216
		
217
	}
218
219
	public void setHidden(boolean hidden) {
220
		// TODO Auto-generated method stub
221
		
222
	}
223
224
	public void setIndention(short indent) {
225
		// TODO Auto-generated method stub
226
		
227
	}
228
229
	public void setLeftBorderColor(short color) {
230
		// TODO Auto-generated method stub
231
		
232
	}
233
234
	public void setLocked(boolean locked) {
235
		// TODO Auto-generated method stub
236
		
237
	}
238
239
	public void setRightBorderColor(short color) {
240
		// TODO Auto-generated method stub
241
		
242
	}
243
244
	public void setRotation(short rotation) {
245
		// TODO Auto-generated method stub
246
		
247
	}
248
249
	public void setTopBorderColor(short color) {
250
		// TODO Auto-generated method stub
251
		
252
	}
253
254
	public void setVerticalAlignment(short align) {
255
		// TODO Auto-generated method stub
256
		
257
	}
258
259
	public void setWrapText(boolean wrapped) {
260
		// TODO Auto-generated method stub
261
		
262
	}
263
264
	private XSSFCellBorder getCellBorder() {
265
		if (cellBorder == null) {
266
			CTBorder border = stylesheet.getBorders().getBorderArray(getBorderId());
267
			cellBorder = new XSSFCellBorder(border);
268
		}
269
		return cellBorder;
270
	}
271
272
	private int getBorderId() {
273
		if (cellXf.isSetBorderId()) {
274
			return (int) cellXf.getBorderId();
275
		}
276
		return (int) cellStyleXf.getBorderId();
277
	}
278
279
	private Enum getBorderStyle(BorderSides side) {
280
		return getCellBorder().getBorderStyle(side);
281
	}
282
283
	private short getBorderColorBySide(BorderSides side) {
284
		return (short) getCellBorder().getBorderColor(side).getIndexed();
285
	}
286
	
287
}
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellBorder.java (+59 lines)
Line 0 Link Here
1
/* ====================================================================
2
   Licensed to the Apache Software Foundation (ASF) under one or more
3
   contributor license agreements.  See the NOTICE file distributed with
4
   this work for additional information regarding copyright ownership.
5
   The ASF licenses this file to You under the Apache License, Version 2.0
6
   (the "License"); you may not use this file except in compliance with
7
   the License.  You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
==================================================================== */
17
package org.apache.poi.xssf.usermodel.extensions;
18
19
20
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder;
21
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorderPr;
22
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STBorderStyle.Enum;
23
24
25
public class XSSFCellBorder {
26
	
27
	private CTBorder border;
28
	
29
	public XSSFCellBorder(CTBorder border) {
30
		this.border = border;
31
	}
32
	
33
	public static enum BorderSides {
34
		TOP, RIGHT, BOTTOM, LEFT
35
	}
36
	
37
	public Enum getBorderStyle(BorderSides side) {
38
		return getBorder(side).getStyle();
39
	}
40
	
41
	public XSSFColor getBorderColor(BorderSides side) {
42
		CTBorderPr borderPr = getBorder(side);
43
		if (!borderPr.isSetColor()) {
44
			borderPr.addNewColor();
45
		}
46
		return new XSSFColor(getBorder(side).getColor());
47
	}
48
	
49
	private CTBorderPr getBorder(BorderSides side) {
50
		switch (side) {
51
		case TOP: return border.getTop();
52
		case RIGHT: return border.getRight();
53
		case BOTTOM: return border.getBottom();
54
		case LEFT: return border.getLeft();
55
		default: throw new IllegalArgumentException("No suitable side specified for the border");
56
		}
57
	}
58
59
}
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellAlignment.java (+47 lines)
Line 0 Link Here
1
/* ====================================================================
2
   Licensed to the Apache Software Foundation (ASF) under one or more
3
   contributor license agreements.  See the NOTICE file distributed with
4
   this work for additional information regarding copyright ownership.
5
   The ASF licenses this file to You under the Apache License, Version 2.0
6
   (the "License"); you may not use this file except in compliance with
7
   the License.  You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
==================================================================== */
17
package org.apache.poi.xssf.usermodel.extensions;
18
19
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellAlignment;
20
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STHorizontalAlignment;
21
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STHorizontalAlignment.Enum;
22
23
24
public class XSSFCellAlignment {
25
	
26
	private CTCellAlignment cellAlignement;
27
	
28
	public XSSFCellAlignment(CTCellAlignment cellAlignment) {
29
		this.cellAlignement = cellAlignment;
30
	}
31
	
32
	public Enum getHorizontal() {
33
		return cellAlignement.getHorizontal();
34
	}
35
	
36
	public void setHorizontal(STHorizontalAlignment.Enum horizontal) {
37
		cellAlignement.setHorizontal(horizontal);
38
	}
39
	
40
	public long getIndent() {
41
		return cellAlignement.getIndent();
42
	}
43
	
44
	public void setIndent(long indent) {
45
		cellAlignement.setIndent(indent);
46
	}
47
}
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFColor.java (+68 lines)
Line 0 Link Here
1
/* ====================================================================
2
   Licensed to the Apache Software Foundation (ASF) under one or more
3
   contributor license agreements.  See the NOTICE file distributed with
4
   this work for additional information regarding copyright ownership.
5
   The ASF licenses this file to You under the Apache License, Version 2.0
6
   (the "License"); you may not use this file except in compliance with
7
   the License.  You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
==================================================================== */
17
package org.apache.poi.xssf.usermodel.extensions;
18
19
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;
20
21
public class XSSFColor {
22
	
23
	private CTColor color;
24
	
25
	public XSSFColor(CTColor color) {
26
		this.color = color;
27
	}
28
	
29
	public boolean isAuto() {
30
		return color.getAuto();
31
	}
32
	
33
	public void setAuto(boolean auto) {
34
		color.setAuto(auto);
35
	}
36
	
37
	public long getIndexed() {
38
		return color.getIndexed();
39
	}
40
	
41
	public void setIndexed(long indexed) {
42
		color.setIndexed(indexed);
43
	}
44
	
45
	public byte[] getRgb() {
46
		return color.getRgb();
47
	}
48
	
49
	public void setRgb(byte[] rgb) {
50
		color.setRgb(rgb);
51
	}
52
	
53
	public long getTheme() {
54
		return color.getTheme();
55
	}
56
	
57
	public void setTheme(long theme) {
58
		color.setTheme(theme);
59
	}
60
	
61
	public double getTint() {
62
		return color.getTint();
63
	}
64
	
65
	public void setTint(double tint) {
66
		color.setTint(tint);
67
	}
68
}
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/ColumnHelper.java (-46 / +136 lines)
Lines 17-30 Link Here
17
17
18
package org.apache.poi.xssf.usermodel.helpers;
18
package org.apache.poi.xssf.usermodel.helpers;
19
19
20
import java.util.Arrays;
20
21
22
import org.apache.poi.xssf.util.CTColComparator;
23
import org.apache.poi.xssf.util.NumericRanges;
21
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol;
24
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol;
22
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols;
25
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols;
23
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
26
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
24
27
28
public class ColumnHelper {
25
29
26
public class ColumnHelper {
27
    
28
    private CTWorksheet worksheet;
30
    private CTWorksheet worksheet;
29
    private CTCols newCols;
31
    private CTCols newCols;
30
32
Lines 38-118 Link Here
38
        this.newCols = CTCols.Factory.newInstance();
40
        this.newCols = CTCols.Factory.newInstance();
39
        CTCols[] colsArray = worksheet.getColsArray();
41
        CTCols[] colsArray = worksheet.getColsArray();
40
        int i = 0;
42
        int i = 0;
41
        for (i = 0 ; i < colsArray.length ; i++) {
43
        for (i = 0; i < colsArray.length; i++) {
42
            CTCols cols = colsArray[i];
44
            CTCols cols = colsArray[i];
43
            CTCol[] colArray = cols.getColArray();
45
            CTCol[] colArray = cols.getColArray();
44
            for (int y = 0 ; y < colArray.length ; y++) {
46
            for (int y = 0; y < colArray.length; y++) {
45
                 CTCol col = colArray[y];
47
                CTCol col = colArray[y];
46
                 for (long k = col.getMin() ; k <= col.getMax() ; k++) {
48
                newCols = addCleanColIntoCols(newCols, col);
47
                     if (!columnExists(newCols, k)) {
48
                         CTCol newCol = newCols.addNewCol();
49
                         newCol.setMin(k);
50
                         newCol.setMax(k);
51
                         setColumnAttributes(col, newCol);
52
                     }
53
                 }
54
            }
49
            }
55
        }
50
        }
56
        for (int y = i-1 ; y >= 0 ; y--) {
51
        for (int y = i - 1; y >= 0; y--) {
57
            worksheet.removeCols(y);
52
            worksheet.removeCols(y);
58
        }
53
        }
59
        worksheet.addNewCols();
54
        worksheet.addNewCols();
60
        worksheet.setColsArray(0, newCols);
55
        worksheet.setColsArray(0, newCols);
61
    }
56
    }
62
    
57
58
    public void sortColumns(CTCols newCols) {
59
        CTCol[] colArray = newCols.getColArray();
60
        Arrays.sort(colArray, new CTColComparator());
61
        newCols.setColArray(colArray);
62
    }
63
64
    public CTCol cloneCol(CTCols cols, CTCol col) {
65
        CTCol newCol = cols.addNewCol();
66
        newCol.setMin(col.getMin());
67
        newCol.setMax(col.getMax());
68
        setColumnAttributes(col, newCol);
69
        return newCol;
70
    }
71
63
    public CTCol getColumn(long index) {
72
    public CTCol getColumn(long index) {
64
        for (int i = 0 ; i < worksheet.getColsArray(0).sizeOfColArray() ; i++) {
73
        for (int i = 0; i < worksheet.getColsArray(0).sizeOfColArray(); i++) {
65
            if (worksheet.getColsArray(0).getColArray(i).getMin() == index) {
74
            if (worksheet.getColsArray(0).getColArray(i).getMin() == index) {
66
                return worksheet.getColsArray(0).getColArray(i);
75
                return worksheet.getColsArray(0).getColArray(i);
67
            }
76
            }
68
        }
77
        }
69
        return  null;
78
        return null;
70
    }
79
    }
71
    
80
81
    public CTCols addCleanColIntoCols(CTCols cols, CTCol col) {
82
        boolean colOverlaps = false;
83
        for (int i = 0; i < cols.sizeOfColArray(); i++) {
84
            CTCol ithCol = cols.getColArray(i);
85
            long[] range1 = { ithCol.getMin(), ithCol.getMax() };
86
            long[] range2 = { col.getMin(), col.getMax() };
87
            long[] overlappingRange = NumericRanges.getOverlappingRange(range1,
88
                    range2);
89
            int overlappingType = NumericRanges.getOverlappingType(range1,
90
                    range2);
91
            // different behavior required for each of the 4 different
92
            // overlapping types
93
            if (overlappingType == NumericRanges.OVERLAPS_1_MINOR) {
94
                ithCol.setMax(overlappingRange[0] - 1);
95
                CTCol rangeCol = insertCol(cols, overlappingRange[0],
96
                        overlappingRange[1], new CTCol[] { ithCol, col });
97
                i++;
98
                CTCol newCol = insertCol(cols, (overlappingRange[1] + 1), col
99
                        .getMax(), new CTCol[] { col });
100
                i++;
101
            } else if (overlappingType == NumericRanges.OVERLAPS_2_MINOR) {
102
                ithCol.setMin(overlappingRange[1] + 1);
103
                CTCol rangeCol = insertCol(cols, overlappingRange[0],
104
                        overlappingRange[1], new CTCol[] { ithCol, col });
105
                i++;
106
                CTCol newCol = insertCol(cols, col.getMin(),
107
                        (overlappingRange[0] - 1), new CTCol[] { col });
108
                i++;
109
            } else if (overlappingType == NumericRanges.OVERLAPS_2_WRAPS) {
110
                setColumnAttributes(col, ithCol);
111
                if (col.getMin() != ithCol.getMin()) {
112
                    CTCol newColBefore = insertCol(cols, col.getMin(), (ithCol
113
                            .getMin() - 1), new CTCol[] { col });
114
                    i++;
115
                }
116
                if (col.getMax() != ithCol.getMax()) {
117
                    CTCol newColAfter = insertCol(cols, (ithCol.getMax() + 1),
118
                            col.getMax(), new CTCol[] { col });
119
                    i++;
120
                }
121
            } else if (overlappingType == NumericRanges.OVERLAPS_1_WRAPS) {
122
                if (col.getMin() != ithCol.getMin()) {
123
                    CTCol newColBefore = insertCol(cols, ithCol.getMin(), (col
124
                            .getMin() - 1), new CTCol[] { ithCol });
125
                    i++;
126
                }
127
                if (col.getMax() != ithCol.getMax()) {
128
                    CTCol newColAfter = insertCol(cols, (col.getMax() + 1),
129
                            ithCol.getMax(), new CTCol[] { ithCol });
130
                    i++;
131
                }
132
                ithCol.setMin(overlappingRange[0]);
133
                ithCol.setMax(overlappingRange[1]);
134
                setColumnAttributes(col, ithCol);
135
            }
136
            if (overlappingType != NumericRanges.NO_OVERLAPS) {
137
                colOverlaps = true;
138
            }
139
        }
140
        if (!colOverlaps) {
141
            CTCol newCol = cloneCol(cols, col);
142
        }
143
        sortColumns(cols);
144
        return cols;
145
    }
146
147
    /*
148
     * Insert a new CTCol at position 0 into cols, setting min=min, max=max and
149
     * copying all the colsWithAttributes array cols attributes into newCol
150
     */
151
    private CTCol insertCol(CTCols cols, long min, long max,
152
            CTCol[] colsWithAttributes) {
153
        CTCol newCol = cols.insertNewCol(0);
154
        newCol.setMin(min);
155
        newCol.setMax(max);
156
        for (CTCol col : colsWithAttributes) {
157
            setColumnAttributes(col, newCol);
158
        }
159
        return newCol;
160
    }
161
72
    public boolean columnExists(CTCols cols, long index) {
162
    public boolean columnExists(CTCols cols, long index) {
73
        for (int i = 0 ; i < cols.sizeOfColArray() ; i++) {
163
        for (int i = 0; i < cols.sizeOfColArray(); i++) {
74
            if (cols.getColArray(i).getMin() == index) {
164
            if (cols.getColArray(i).getMin() == index) {
75
                return true;
165
                return true;
76
            }
166
            }
77
        }
167
        }
78
        return false;
168
        return false;
79
    }
169
    }
80
    
170
81
    public void setColumnAttributes(CTCol col, CTCol newCol) {
171
    public void setColumnAttributes(CTCol fromCol, CTCol toCol) {
82
        if (col.getWidth() != 0) {
172
        if (fromCol.getWidth() != 0) {
83
            newCol.setWidth(col.getWidth());
173
            toCol.setWidth(fromCol.getWidth());
84
        }
174
        }
85
        if (col.getHidden()) {
175
        if (fromCol.getHidden()) {
86
            newCol.setHidden(true);
176
            toCol.setHidden(true);
87
        }
177
        }
88
        if (col.getBestFit()) {
178
        if (fromCol.getBestFit()) {
89
            newCol.setBestFit(true);
179
            toCol.setBestFit(true);
90
        }
180
        }
91
    }
181
    }
92
    
182
93
    public void setColBestFit(long index, boolean bestFit) {
183
    public void setColBestFit(long index, boolean bestFit) {
94
    	CTCol col = getOrCreateColumn(index);
184
        CTCol col = getOrCreateColumn(index);
95
    	col.setBestFit(bestFit);
185
        col.setBestFit(bestFit);
96
    }
186
    }
97
    
187
98
    public void setColWidth(long index, double width) {
188
    public void setColWidth(long index, double width) {
99
    	CTCol col = getOrCreateColumn(index);
189
        CTCol col = getOrCreateColumn(index);
100
    	col.setWidth(width);
190
        col.setWidth(width);
101
    }
191
    }
102
    
192
103
    public void setColHidden(long index, boolean hidden) {
193
    public void setColHidden(long index, boolean hidden) {
104
    	CTCol col = getOrCreateColumn(index);
194
        CTCol col = getOrCreateColumn(index);
105
    	col.setHidden(hidden);
195
        col.setHidden(hidden);
106
    }
196
    }
107
197
108
	protected CTCol getOrCreateColumn(long index) {
198
    protected CTCol getOrCreateColumn(long index) {
109
		CTCol col = getColumn(index);
199
        CTCol col = getColumn(index);
110
    	if (col == null) {
200
        if (col == null) {
111
    		col = worksheet.getColsArray(0).addNewCol();
201
            col = worksheet.getColsArray(0).addNewCol();
112
    		col.setMin(index);
202
            col.setMin(index);
113
    		col.setMax(index);
203
            col.setMax(index);
114
    	}
204
        }
115
    	return col;
205
        return col;
116
	}
206
    }
117
    
207
118
}
208
}
(-)src/ooxml/java/org/apache/poi/xssf/util/NumericRanges.java (+66 lines)
Line 0 Link Here
1
/* ====================================================================
2
   Licensed to the Apache Software Foundation (ASF) under one or more
3
   contributor license agreements.  See the NOTICE file distributed with
4
   this work for additional information regarding copyright ownership.
5
   The ASF licenses this file to You under the Apache License, Version 2.0
6
   (the "License"); you may not use this file except in compliance with
7
   the License.  You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
==================================================================== */
17
18
package org.apache.poi.xssf.util;
19
20
public class NumericRanges {
21
22
    public static int NO_OVERLAPS = -1;
23
    public static int OVERLAPS_1_MINOR = 0;
24
    public static int OVERLAPS_2_MINOR = 1;
25
    public static int OVERLAPS_1_WRAPS = 2;
26
    public static int OVERLAPS_2_WRAPS = 3;
27
    
28
    public static long[] getOverlappingRange(long[] range1, long[] range2) {
29
        int overlappingType = getOverlappingType(range1, range2);
30
        if (overlappingType == OVERLAPS_1_MINOR) {
31
            return new long[]{range2[0], range1[1]};
32
        }
33
        else if (overlappingType == OVERLAPS_2_MINOR) {
34
            return new long[]{range1[0], range2[1]};
35
        }
36
        else if (overlappingType == OVERLAPS_2_WRAPS) {
37
            return range1;
38
        }
39
        else if (overlappingType == OVERLAPS_1_WRAPS) {
40
            return range2;
41
        }
42
        return new long[]{-1, -1};
43
    }
44
    
45
    public static int getOverlappingType(long[] range1, long[] range2) {
46
        long min1 = range1[0];
47
        long max1 = range1[1];
48
        long min2 = range2[0];
49
        long max2 = range2[1];
50
        if (min1 >= min2 && max1 <= max2) {
51
            return OVERLAPS_2_WRAPS;
52
        }
53
        else if (min2 >= min1 && max2 <= max1) {
54
            return OVERLAPS_1_WRAPS;
55
        }
56
        else if ((min2 >= min1 && min2 <= max1) && max2 >= max1) {
57
            return OVERLAPS_1_MINOR;
58
        }
59
        else if ((min1 >= min2 && min1 <= max2)  && max1 >= max2) {
60
            return OVERLAPS_2_MINOR;
61
        }
62
        return NO_OVERLAPS;
63
        
64
    }
65
    
66
}
(-)src/ooxml/java/org/apache/poi/xssf/util/CTColComparator.java (+46 lines)
Line 0 Link Here
1
/* ====================================================================
2
   Licensed to the Apache Software Foundation (ASF) under one or more
3
   contributor license agreements.  See the NOTICE file distributed with
4
   this work for additional information regarding copyright ownership.
5
   The ASF licenses this file to You under the Apache License, Version 2.0
6
   (the "License"); you may not use this file except in compliance with
7
   the License.  You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
==================================================================== */
17
18
package org.apache.poi.xssf.util;
19
20
import java.util.Comparator;
21
22
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol;
23
24
public class CTColComparator implements Comparator<CTCol>{
25
26
    public int compare(CTCol o1, CTCol o2) {
27
        if (o1.getMin() < o2.getMin()) {
28
            return -1;
29
        }
30
        else if (o1.getMin() > o2.getMin()) {
31
            return 1;
32
        }
33
        else {
34
            if (o1.getMax() < o2.getMax()) {
35
                return -1;
36
            }
37
            if (o1.getMax() > o2.getMax()) {
38
                return 1;
39
            }
40
            return 0;
41
        }
42
    }
43
    
44
    
45
    
46
}
(-)src/ooxml/testcases/org/apache/poi/xssf/usermodel/extensions/TestXSSFBorder.java (+48 lines)
Line 0 Link Here
1
/* ====================================================================
2
   Licensed to the Apache Software Foundation (ASF) under one or more
3
   contributor license agreements.  See the NOTICE file distributed with
4
   this work for additional information regarding copyright ownership.
5
   The ASF licenses this file to You under the Apache License, Version 2.0
6
   (the "License"); you may not use this file except in compliance with
7
   the License.  You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
==================================================================== */
17
18
package org.apache.poi.xssf.usermodel.extensions;
19
20
import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder.BorderSides;
21
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder;
22
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorderPr;
23
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTStylesheet;
24
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STBorderStyle;
25
26
import junit.framework.TestCase;
27
28
29
public class TestXSSFBorder extends TestCase {
30
	
31
	public void testGetBorderStyle() {
32
		CTStylesheet stylesheet = CTStylesheet.Factory.newInstance();
33
		CTBorder border = stylesheet.addNewBorders().addNewBorder();
34
		CTBorderPr top = border.addNewTop();
35
		CTBorderPr right = border.addNewRight();
36
		CTBorderPr bottom = border.addNewBottom();
37
		top.setStyle(STBorderStyle.DASH_DOT);
38
		right.setStyle(STBorderStyle.NONE);
39
		bottom.setStyle(STBorderStyle.THIN);
40
		XSSFCellBorder cellBorderStyle = new XSSFCellBorder(border);
41
		assertEquals("dashDot", cellBorderStyle.getBorderStyle(BorderSides.TOP).toString());
42
		assertEquals("none", cellBorderStyle.getBorderStyle(BorderSides.RIGHT).toString());
43
		assertEquals(1, cellBorderStyle.getBorderStyle(BorderSides.RIGHT).intValue());
44
		assertEquals("thin", cellBorderStyle.getBorderStyle(BorderSides.BOTTOM).toString());
45
		assertEquals(2, cellBorderStyle.getBorderStyle(BorderSides.BOTTOM).intValue());
46
	}
47
	
48
}
(-)src/ooxml/testcases/org/apache/poi/xssf/usermodel/helpers/TestColumnHelper.java (-19 / +140 lines)
Lines 25-36 Link Here
25
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols;
25
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols;
26
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
26
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
27
27
28
public class TestColumnHelper extends TestCase {
28
29
29
public class TestColumnHelper extends TestCase {
30
    
31
    public void testCleanColumns() {
30
    public void testCleanColumns() {
32
        CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
31
        CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
33
        
32
34
        CTCols cols1 = worksheet.addNewCols();
33
        CTCols cols1 = worksheet.addNewCols();
35
        CTCol col1 = cols1.addNewCol();
34
        CTCol col1 = cols1.addNewCol();
36
        col1.setMin(1);
35
        col1.setMin(1);
Lines 42-67 Link Here
42
        col2.setMax(3);
41
        col2.setMax(3);
43
        CTCols cols2 = worksheet.addNewCols();
42
        CTCols cols2 = worksheet.addNewCols();
44
        CTCol col4 = cols2.addNewCol();
43
        CTCol col4 = cols2.addNewCol();
45
        col4.setMin(3);
44
        col4.setMin(13);
46
        col4.setMax(6);
45
        col4.setMax(16384);
47
        
46
48
        // Test cleaning cols
47
        // Test cleaning cols
49
        assertEquals(2, worksheet.sizeOfColsArray());
48
        assertEquals(2, worksheet.sizeOfColsArray());
50
        int count = countColumns(worksheet);
49
        int count = countColumns(worksheet);
51
        assertEquals(7, count);
50
        assertEquals(16375, count);
52
        // Clean columns and test a clean worksheet
51
        // Clean columns and test a clean worksheet
53
        ColumnHelper helper = new ColumnHelper(worksheet);
52
        ColumnHelper helper = new ColumnHelper(worksheet);
54
        assertEquals(1, worksheet.sizeOfColsArray());
53
        assertEquals(1, worksheet.sizeOfColsArray());
55
        count = countColumns(worksheet);
54
        count = countColumns(worksheet);
56
        assertEquals(6, count);
55
        assertEquals(16375, count);
57
        assertEquals((double) 88, helper.getColumn(1).getWidth());
56
        assertEquals((double) 88, helper.getColumn(1).getWidth());
58
        assertTrue(helper.getColumn(1).getHidden());
57
        assertTrue(helper.getColumn(1).getHidden());
59
        
60
    }
58
    }
61
    
59
60
    public void testSortColumns() {
61
        CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
62
        ColumnHelper helper = new ColumnHelper(worksheet);
63
64
        CTCols cols1 = CTCols.Factory.newInstance();
65
        CTCol col1 = cols1.addNewCol();
66
        col1.setMin(1);
67
        col1.setMax(1);
68
        col1.setWidth(88);
69
        col1.setHidden(true);
70
        CTCol col2 = cols1.addNewCol();
71
        col2.setMin(2);
72
        col2.setMax(3);
73
        CTCol col3 = cols1.addNewCol();
74
        col3.setMin(13);
75
        col3.setMax(16750);
76
        assertEquals(3, cols1.sizeOfColArray());
77
        CTCol col4 = cols1.addNewCol();
78
        col4.setMin(8);
79
        col4.setMax(11);
80
        assertEquals(4, cols1.sizeOfColArray());
81
        CTCol col5 = cols1.addNewCol();
82
        col5.setMin(4);
83
        col5.setMax(5);
84
        assertEquals(5, cols1.sizeOfColArray());
85
        CTCol col6 = cols1.addNewCol();
86
        col6.setMin(8);
87
        col6.setMax(9);
88
        col6.setHidden(true);
89
        CTCol col7 = cols1.addNewCol();
90
        col7.setMin(6);
91
        col7.setMax(8);
92
        col7.setWidth(17.0);
93
        CTCol col8 = cols1.addNewCol();
94
        col8.setMin(25);
95
        col8.setMax(27);
96
        CTCol col9 = cols1.addNewCol();
97
        col9.setMin(20);
98
        col9.setMax(30);
99
        assertEquals(9, cols1.sizeOfColArray());
100
        assertEquals(20, cols1.getColArray(8).getMin());
101
        assertEquals(30, cols1.getColArray(8).getMax());
102
        helper.sortColumns(cols1);
103
        assertEquals(9, cols1.sizeOfColArray());
104
        assertEquals(25, cols1.getColArray(8).getMin());
105
        assertEquals(27, cols1.getColArray(8).getMax());
106
    }
107
108
    public void testCloneCol() {
109
        CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
110
        ColumnHelper helper = new ColumnHelper(worksheet);
111
112
        CTCols cols = CTCols.Factory.newInstance();
113
        CTCol col = CTCol.Factory.newInstance();
114
        col.setMin(2);
115
        col.setMax(8);
116
        col.setHidden(true);
117
        col.setWidth(13.4);
118
        CTCol newCol = helper.cloneCol(cols, col);
119
        assertEquals(2, newCol.getMin());
120
        assertEquals(8, newCol.getMax());
121
        assertTrue(newCol.getHidden());
122
        assertEquals(13.4, newCol.getWidth());
123
    }
124
125
    public void testAddCleanColIntoCols() {
126
        CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
127
        ColumnHelper helper = new ColumnHelper(worksheet);
128
129
        CTCols cols1 = CTCols.Factory.newInstance();
130
        CTCol col1 = cols1.addNewCol();
131
        col1.setMin(1);
132
        col1.setMax(1);
133
        col1.setWidth(88);
134
        col1.setHidden(true);
135
        CTCol col2 = cols1.addNewCol();
136
        col2.setMin(2);
137
        col2.setMax(3);
138
        CTCol col3 = cols1.addNewCol();
139
        col3.setMin(13);
140
        col3.setMax(16750);
141
        assertEquals(3, cols1.sizeOfColArray());
142
        CTCol col4 = cols1.addNewCol();
143
        col4.setMin(8);
144
        col4.setMax(9);
145
        assertEquals(4, cols1.sizeOfColArray());
146
147
        CTCol col5 = CTCol.Factory.newInstance();
148
        col5.setMin(4);
149
        col5.setMax(5);
150
        helper.addCleanColIntoCols(cols1, col5);
151
        assertEquals(5, cols1.sizeOfColArray());
152
153
        CTCol col6 = CTCol.Factory.newInstance();
154
        col6.setMin(8);
155
        col6.setMax(11);
156
        col6.setHidden(true);
157
        helper.addCleanColIntoCols(cols1, col6);
158
        assertEquals(6, cols1.sizeOfColArray());
159
160
        CTCol col7 = CTCol.Factory.newInstance();
161
        col7.setMin(6);
162
        col7.setMax(8);
163
        col7.setWidth(17.0);
164
        helper.addCleanColIntoCols(cols1, col7);
165
        assertEquals(8, cols1.sizeOfColArray());
166
167
        CTCol col8 = CTCol.Factory.newInstance();
168
        col8.setMin(20);
169
        col8.setMax(30);
170
        helper.addCleanColIntoCols(cols1, col8);
171
        assertEquals(10, cols1.sizeOfColArray());
172
173
        CTCol col9 = CTCol.Factory.newInstance();
174
        col9.setMin(25);
175
        col9.setMax(27);
176
        helper.addCleanColIntoCols(cols1, col9);
177
178
        System.err.println(cols1);
179
    }
180
62
    public void testGetColumn() {
181
    public void testGetColumn() {
63
        CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
182
        CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
64
        
183
65
        CTCols cols1 = worksheet.addNewCols();
184
        CTCols cols1 = worksheet.addNewCols();
66
        CTCol col1 = cols1.addNewCol();
185
        CTCol col1 = cols1.addNewCol();
67
        col1.setMin(1);
186
        col1.setMin(1);
Lines 75-81 Link Here
75
        CTCol col4 = cols2.addNewCol();
194
        CTCol col4 = cols2.addNewCol();
76
        col4.setMin(3);
195
        col4.setMin(3);
77
        col4.setMax(6);
196
        col4.setMax(6);
78
        
197
79
        ColumnHelper helper = new ColumnHelper(worksheet);
198
        ColumnHelper helper = new ColumnHelper(worksheet);
80
        assertNotNull(helper.getColumn(1));
199
        assertNotNull(helper.getColumn(1));
81
        assertEquals((double) 88, helper.getColumn(1).getWidth());
200
        assertEquals((double) 88, helper.getColumn(1).getWidth());
Lines 83-89 Link Here
83
        assertFalse(helper.getColumn(2).getHidden());
202
        assertFalse(helper.getColumn(2).getHidden());
84
        assertNull(helper.getColumn(99));
203
        assertNull(helper.getColumn(99));
85
    }
204
    }
86
    
205
87
    public void testSetColumnAttributes() {
206
    public void testSetColumnAttributes() {
88
        CTCol col = CTCol.Factory.newInstance();
207
        CTCol col = CTCol.Factory.newInstance();
89
        col.setWidth(12);
208
        col.setWidth(12);
Lines 91-102 Link Here
91
        CTCol newCol = CTCol.Factory.newInstance();
210
        CTCol newCol = CTCol.Factory.newInstance();
92
        assertEquals((double) 0, newCol.getWidth());
211
        assertEquals((double) 0, newCol.getWidth());
93
        assertFalse(newCol.getHidden());
212
        assertFalse(newCol.getHidden());
94
        ColumnHelper helper = new ColumnHelper(CTWorksheet.Factory.newInstance());
213
        ColumnHelper helper = new ColumnHelper(CTWorksheet.Factory
214
                .newInstance());
95
        helper.setColumnAttributes(col, newCol);
215
        helper.setColumnAttributes(col, newCol);
96
        assertEquals((double) 12, newCol.getWidth());
216
        assertEquals((double) 12, newCol.getWidth());
97
        assertTrue(newCol.getHidden());
217
        assertTrue(newCol.getHidden());
98
    }
218
    }
99
    
219
100
    public void testGetOrCreateColumn() {
220
    public void testGetOrCreateColumn() {
101
        XSSFWorkbook workbook = new XSSFWorkbook();
221
        XSSFWorkbook workbook = new XSSFWorkbook();
102
        XSSFSheet sheet = (XSSFSheet) workbook.createSheet("Sheet 1");
222
        XSSFSheet sheet = (XSSFSheet) workbook.createSheet("Sheet 1");
Lines 113-126 Link Here
113
    private int countColumns(CTWorksheet worksheet) {
233
    private int countColumns(CTWorksheet worksheet) {
114
        int count;
234
        int count;
115
        count = 0;
235
        count = 0;
116
        for (int i = 0 ; i < worksheet.sizeOfColsArray() ; i++) {
236
        for (int i = 0; i < worksheet.sizeOfColsArray(); i++) {
117
            for (int y = 0 ; y < worksheet.getColsArray(i).sizeOfColArray() ; y++) {
237
            for (int y = 0; y < worksheet.getColsArray(i).sizeOfColArray(); y++) {
118
                for (long k = worksheet.getColsArray(i).getColArray(y).getMin() ; k <= worksheet.getColsArray(i).getColArray(y).getMax() ; k++) {
238
                for (long k = worksheet.getColsArray(i).getColArray(y).getMin(); k <= worksheet
239
                        .getColsArray(i).getColArray(y).getMax(); k++) {
119
                    count++;
240
                    count++;
120
                }
241
                }
121
            }
242
            }
122
        }
243
        }
123
        return count;
244
        return count;
124
    }
245
    }
125
    
246
126
}
247
}
(-)src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java (+85 lines)
Line 0 Link Here
1
/* ====================================================================
2
   Licensed to the Apache Software Foundation (ASF) under one or more
3
   contributor license agreements.  See the NOTICE file distributed with
4
   this work for additional information regarding copyright ownership.
5
   The ASF licenses this file to You under the Apache License, Version 2.0
6
   (the "License"); you may not use this file except in compliance with
7
   the License.  You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
==================================================================== */
17
18
package org.apache.poi.xssf.usermodel;
19
20
import junit.framework.TestCase;
21
22
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder;
23
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTStylesheet;
24
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf;
25
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STBorderStyle;
26
27
28
public class TestXSSFCellStyle extends TestCase {
29
	
30
	private CTStylesheet ctStylesheet;
31
	private CTBorder ctBorder;
32
	private CTXf cellStyleXf;
33
	private CTXf cellXf;
34
	private XSSFCellStyle cellStyle;
35
36
	public void setUp() {
37
		ctStylesheet = CTStylesheet.Factory.newInstance();
38
		ctBorder = ctStylesheet.addNewBorders().insertNewBorder(0);
39
		cellStyleXf = ctStylesheet.addNewCellStyleXfs().addNewXf();
40
		cellStyleXf.setBorderId(0);
41
		cellXf = ctStylesheet.addNewCellXfs().addNewXf();
42
		cellXf.setXfId(0);
43
		cellStyle = new XSSFCellStyle(ctStylesheet, 0);
44
	}
45
	
46
	public void testGetBorderBottom() {		
47
		ctBorder.addNewBottom().setStyle(STBorderStyle.THIN);
48
		assertEquals((short)1, cellStyle.getBorderBottom());
49
	}
50
51
	public void testGetBorderBottomAsString() {
52
		ctBorder.addNewBottom().setStyle(STBorderStyle.THIN);
53
		assertEquals("thin", cellStyle.getBorderBottomAsString());
54
	}
55
	
56
	public void testGetBorderRight() {
57
		ctBorder.addNewRight().setStyle(STBorderStyle.MEDIUM);
58
		assertEquals((short)2, cellStyle.getBorderRight());
59
	}
60
61
	public void testGetBorderRightAsString() {
62
		ctBorder.addNewRight().setStyle(STBorderStyle.MEDIUM);
63
		assertEquals("medium", cellStyle.getBorderRightAsString());
64
	}
65
	
66
	public void testGetBorderLeft() {
67
		ctBorder.addNewLeft().setStyle(STBorderStyle.DASHED);
68
		assertEquals((short)3, cellStyle.getBorderLeft());
69
	}
70
71
	public void testGetBorderLeftAsString() {
72
		ctBorder.addNewLeft().setStyle(STBorderStyle.DASHED);
73
		assertEquals("dashed", cellStyle.getBorderLeftAsString());
74
	}
75
	
76
	public void testGetBorderTop() {
77
		ctBorder.addNewTop().setStyle(STBorderStyle.HAIR);
78
		assertEquals((short)7, cellStyle.getBorderTop());
79
	}
80
81
	public void testGetTopBottomAsString() {
82
		ctBorder.addNewTop().setStyle(STBorderStyle.HAIR);
83
		assertEquals("hair", cellStyle.getBorderTopAsString());
84
	}
85
}
(-)src/ooxml/testcases/org/apache/poi/xssf/io/TestLoadSaveXSSF.java (-3 / +3 lines)
Lines 37-43 Link Here
37
    protected void setUp() throws Exception {
37
    protected void setUp() throws Exception {
38
        super.setUp();
38
        super.setUp();
39
        System.setProperty("org.apache.poi.util.POILogger", org.apache.poi.util.CommonsLogger.class.getName());
39
        System.setProperty("org.apache.poi.util.POILogger", org.apache.poi.util.CommonsLogger.class.getName());
40
        filename = System.getProperty("HSSF.testdata.path");
40
        filename = System.getProperty("XSSF.testdata.path");
41
        if (filename == null) {
41
        if (filename == null) {
42
            filename = "src/ooxml/testcases/org/apache/poi/xssf/data";
42
            filename = "src/ooxml/testcases/org/apache/poi/xssf/data";
43
        }
43
        }
Lines 58-64 Link Here
58
    
58
    
59
    // TODO filename string hard coded in XSSFWorkbook constructor in order to make ant test-ooxml target be successfull.
59
    // TODO filename string hard coded in XSSFWorkbook constructor in order to make ant test-ooxml target be successfull.
60
    public void testLoadStyles() throws Exception {
60
    public void testLoadStyles() throws Exception {
61
        XSSFWorkbook workbook = new XSSFWorkbook(new File("src/ooxml/testcases/org/apache/poi/xssf/data", "styles.xlsx").getAbsolutePath());
61
        XSSFWorkbook workbook = new XSSFWorkbook(new File(filename, "styles.xlsx").getAbsolutePath());
62
        Sheet sheet = workbook.getSheetAt(0);
62
        Sheet sheet = workbook.getSheetAt(0);
63
        Row row = sheet.getRow(0);
63
        Row row = sheet.getRow(0);
64
        Cell cell = row.getCell((short) 0);
64
        Cell cell = row.getCell((short) 0);
Lines 68-74 Link Here
68
68
69
    // TODO filename string hard coded in XSSFWorkbook constructor in order to make ant test-ooxml target be successfull.
69
    // TODO filename string hard coded in XSSFWorkbook constructor in order to make ant test-ooxml target be successfull.
70
    public void testLoadPictures() throws Exception {
70
    public void testLoadPictures() throws Exception {
71
        XSSFWorkbook workbook = new XSSFWorkbook(new File("src/ooxml/testcases/org/apache/poi/xssf/data", "picture.xlsx").getAbsolutePath());
71
        XSSFWorkbook workbook = new XSSFWorkbook(new File(filename, "picture.xlsx").getAbsolutePath());
72
        List<PictureData> pictures = workbook.getAllPictures();
72
        List<PictureData> pictures = workbook.getAllPictures();
73
        assertEquals(1, pictures.size());
73
        assertEquals(1, pictures.size());
74
    }
74
    }
(-)src/ooxml/testcases/org/apache/poi/xssf/util/TestNumericRanges.java (+58 lines)
Line 0 Link Here
1
/* ====================================================================
2
   Licensed to the Apache Software Foundation (ASF) under one or more
3
   contributor license agreements.  See the NOTICE file distributed with
4
   this work for additional information regarding copyright ownership.
5
   The ASF licenses this file to You under the Apache License, Version 2.0
6
   (the "License"); you may not use this file except in compliance with
7
   the License.  You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
==================================================================== */
17
18
package org.apache.poi.xssf.util;
19
20
import junit.framework.TestCase;
21
22
23
public class TestNumericRanges extends TestCase {
24
    
25
    public void testGetOverlappingType() {
26
        long[] r1 = {3, 8};
27
        long[] r2 = {6, 11};
28
        long[] r3 = {1, 5};
29
        long[] r4 = {2, 20};
30
        long[] r5 = {5, 6};
31
        long[] r6 = {20, 23};
32
        assertEquals(NumericRanges.OVERLAPS_1_MINOR, NumericRanges.getOverlappingType(r1, r2));
33
        assertEquals(NumericRanges.OVERLAPS_2_MINOR, NumericRanges.getOverlappingType(r1, r3));
34
        assertEquals(NumericRanges.OVERLAPS_2_WRAPS, NumericRanges.getOverlappingType(r1, r4));
35
        assertEquals(NumericRanges.OVERLAPS_1_WRAPS, NumericRanges.getOverlappingType(r1, r5));
36
        assertEquals(NumericRanges.NO_OVERLAPS, NumericRanges.getOverlappingType(r1, r6));
37
    }
38
    
39
    public void testGetOverlappingRange() {
40
        long[] r1 = {3, 8};
41
        long[] r2 = {6, 11};
42
        long[] r3 = {1, 5};
43
        long[] r4 = {2, 20};
44
        long[] r5 = {5, 6};
45
        long[] r6 = {20, 23};
46
        assertEquals(6, NumericRanges.getOverlappingRange(r1, r2)[0]);
47
        assertEquals(8, NumericRanges.getOverlappingRange(r1, r2)[1]);
48
        assertEquals(3, NumericRanges.getOverlappingRange(r1, r3)[0]);
49
        assertEquals(5, NumericRanges.getOverlappingRange(r1, r3)[1]);
50
        assertEquals(3, NumericRanges.getOverlappingRange(r1, r4)[0]);
51
        assertEquals(8, NumericRanges.getOverlappingRange(r1, r4)[1]);
52
        assertEquals(5, NumericRanges.getOverlappingRange(r1, r5)[0]);
53
        assertEquals(6, NumericRanges.getOverlappingRange(r1, r5)[1]);
54
        assertEquals(-1, NumericRanges.getOverlappingRange(r1, r6)[0]);
55
        assertEquals(-1, NumericRanges.getOverlappingRange(r1, r6)[1]);
56
    }
57
    
58
}
(-)src/ooxml/testcases/org/apache/poi/xssf/util/TestCTColComparator.java (+77 lines)
Line 0 Link Here
1
/* ====================================================================
2
   Licensed to the Apache Software Foundation (ASF) under one or more
3
   contributor license agreements.  See the NOTICE file distributed with
4
   this work for additional information regarding copyright ownership.
5
   The ASF licenses this file to You under the Apache License, Version 2.0
6
   (the "License"); you may not use this file except in compliance with
7
   the License.  You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
==================================================================== */
17
18
package org.apache.poi.xssf.util;
19
20
import java.util.Arrays;
21
22
import junit.framework.TestCase;
23
24
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol;
25
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols;
26
27
28
public class TestCTColComparator extends TestCase {
29
    
30
    public void testCompare() {
31
        CTColComparator comparator = new CTColComparator();
32
        CTCol o1 = CTCol.Factory.newInstance();
33
        o1.setMin(1);
34
        o1.setMax(10);
35
        CTCol o2 = CTCol.Factory.newInstance();
36
        o2.setMin(11);
37
        o2.setMax(12);
38
        assertEquals(-1, comparator.compare(o1, o2));
39
        CTCol o3 = CTCol.Factory.newInstance();
40
        o3.setMin(5);
41
        o3.setMax(8);
42
        CTCol o4 = CTCol.Factory.newInstance();
43
        o4.setMin(5);
44
        o4.setMax(80);
45
        assertEquals(-1, comparator.compare(o3, o4));
46
    }
47
    
48
    public void testArraysSort() {
49
        CTColComparator comparator = new CTColComparator();
50
        CTCol o1 = CTCol.Factory.newInstance();
51
        o1.setMin(1);
52
        o1.setMax(10);
53
        CTCol o2 = CTCol.Factory.newInstance();
54
        o2.setMin(11);
55
        o2.setMax(12);
56
        assertEquals(-1, comparator.compare(o1, o2));
57
        CTCol o3 = CTCol.Factory.newInstance();
58
        o3.setMin(5);
59
        o3.setMax(80);
60
        CTCol o4 = CTCol.Factory.newInstance();
61
        o4.setMin(5);
62
        o4.setMax(8);
63
        assertEquals(1, comparator.compare(o3, o4));
64
        CTCol[] cols = new CTCol[4];
65
        cols[0] = o1;
66
        cols[1] = o2;
67
        cols[2] = o3;
68
        cols[3] = o4;
69
        assertEquals(80, cols[2].getMax());
70
        assertEquals(8, cols[3].getMax());
71
        Arrays.sort(cols, comparator);
72
        assertEquals(12, cols[3].getMax());
73
        assertEquals(8, cols[1].getMax());
74
        assertEquals(80, cols[2].getMax());
75
    }
76
    
77
}

Return to bug 44581