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 |
} |