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

(-)a/src/ooxml/java/org/apache/poi/xssf/streaming/reader/StreamedCell.java (+528 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.streaming.reader;
18
19
import java.util.Calendar;
20
import java.util.Date;
21
22
import org.apache.poi.ss.formula.FormulaParseException;
23
import org.apache.poi.ss.usermodel.Cell;
24
import org.apache.poi.ss.usermodel.CellStyle;
25
import org.apache.poi.ss.usermodel.CellType;
26
import org.apache.poi.ss.usermodel.Comment;
27
import org.apache.poi.ss.usermodel.Hyperlink;
28
import org.apache.poi.ss.usermodel.RichTextString;
29
import org.apache.poi.ss.usermodel.Row;
30
import org.apache.poi.ss.usermodel.Sheet;
31
import org.apache.poi.ss.util.CellAddress;
32
import org.apache.poi.ss.util.CellRangeAddress;
33
import org.apache.poi.util.NotImplemented;
34
35
/**
36
 * Represents cell in a row
37
 * Value of cell is represented as a string.
38
 *
39
 */
40
public class StreamedCell  implements Cell{
41
    private String value;
42
    private int cellNumber;
43
    private CellType cellType;
44
    
45
    public StreamedCell(){
46
        
47
    }
48
49
    /**
50
     * <pre>
51
     * Return cell value
52
     * </pre>
53
     * Return the value of a cell in String format.
54
     * Value will be same as how it is represented in excel.
55
     * @return String
56
     */
57
    public String getValue() {
58
        return value;
59
    }
60
61
    public void setValue(String value) {
62
        this.value = value;
63
    }
64
    
65
    public String toString(){
66
        return value;
67
    }
68
69
    /**
70
     * <pre>
71
     * Returns the cell number
72
     * </pre>
73
     *
74
     * @return int, that represents cell number
75
     */
76
    public int getCellNumber() {
77
        return cellNumber;
78
    }
79
80
    /**
81
     * <pre>
82
     * Not supported right now, as StreamedWorkbook
83
     * supports only reading.
84
     *</pre>
85
     * @param cellNumber
86
     */
87
    public void setCellNumber(int cellNumber) {
88
        this.cellNumber = cellNumber;
89
    }
90
91
    /**
92
     *  <pre>
93
     * Returns the column index of the cell.
94
     *  </pre>
95
     *  @return int that represents cell number
96
     */
97
    public int getColumnIndex() {
98
        return this.cellNumber;
99
    }
100
101
    /**
102
     *  <pre>
103
     * Will be supported in future.
104
     *  </pre>
105
     *  @exception UnsupportedOperationException
106
     */
107
    @NotImplemented
108
    public int getRowIndex() {
109
        throw new UnsupportedOperationException("Not implememted yet.");
110
    }
111
112
    /**
113
     *  <pre>
114
     * Will be supported in future.
115
     *  </pre>
116
     *  @exception UnsupportedOperationException
117
     */
118
    @NotImplemented
119
    public Sheet getSheet() {
120
        throw new UnsupportedOperationException("Not implememted yet.");
121
    }
122
123
    /**
124
     *  <pre>
125
     * Will be supported in future.
126
     *  </pre>
127
     *  @exception UnsupportedOperationException
128
     */
129
    @NotImplemented
130
    public Row getRow() {
131
        throw new UnsupportedOperationException("Not implememted yet.");
132
    }
133
134
    /**
135
     * <pre>
136
     * Not supported right now, as StreamedWorkbook
137
     * supports only reading.
138
     *</pre>
139
     * @param cellType
140
     * @exception UnsupportedOperationException
141
     */
142
    @NotImplemented
143
    public void setCellType(int cellType) {
144
        throw new UnsupportedOperationException("Operation not supported.");
145
    }
146
147
    /**
148
     * <pre>
149
     * Not supported right now, as StreamedWorkbook
150
     * supports only reading.
151
     *</pre>
152
     * @param cellType
153
     */
154
    @NotImplemented
155
    public void setCellType(CellType cellType) {
156
        //to avoid setting this by user
157
        if(this.cellType == null)
158
        this.cellType = cellType;
159
    }
160
161
    /**
162
     *  <pre>
163
     * Will be supported in future.
164
     *  </pre>
165
     *  @exception UnsupportedOperationException
166
     */
167
    @NotImplemented
168
    public int getCellType() {
169
        throw new UnsupportedOperationException("Not implememted yet.");
170
    }
171
172
    /**
173
     *  <pre>
174
     * Return the cell type.
175
     *  </pre>
176
     *  
177
     *  @return CellType
178
     */
179
    @NotImplemented
180
    public CellType getCellTypeEnum() {
181
        return cellType;
182
    }
183
184
    /**
185
     *  <pre>
186
     * Will be supported in future.
187
     *  </pre>
188
     *  @exception UnsupportedOperationException
189
     */
190
    @NotImplemented
191
    public int getCachedFormulaResultType() {
192
        throw new UnsupportedOperationException("Not implememted yet.");
193
    }
194
195
    /**
196
     *  <pre>
197
     * Will be supported in future.
198
     *  </pre>
199
     *  @exception UnsupportedOperationException
200
     */
201
    @NotImplemented
202
    public CellType getCachedFormulaResultTypeEnum() {
203
        throw new UnsupportedOperationException("Not implememted yet.");
204
    }
205
206
    /**
207
     * <pre>
208
     * Not supported right now, as StreamedWorkbook
209
     * supports only reading.
210
     *</pre>
211
     * @param value
212
     * @exception UnsupportedOperationException
213
     */
214
    @NotImplemented
215
    public void setCellValue(double value) {
216
        throw new UnsupportedOperationException("Operation not supported.");
217
    }
218
219
    /**
220
     * <pre>
221
     * Not supported right now, as StreamedWorkbook
222
     * supports only reading.
223
     *</pre>
224
     * @param value
225
     * @exception UnsupportedOperationException
226
     */
227
    @NotImplemented
228
    public void setCellValue(Date value) {
229
        throw new UnsupportedOperationException("Operation not supported.");
230
    }
231
232
    /**
233
     * <pre>
234
     * Not supported right now, as StreamedWorkbook
235
     * supports only reading.
236
     *</pre>
237
     *@exception UnsupportedOperationException
238
     */
239
    @NotImplemented
240
    public void setCellValue(Calendar value) {
241
        throw new UnsupportedOperationException("Operation not supported.");
242
    }
243
244
    /**
245
     * <pre>
246
     * Not supported right now, as StreamedWorkbook
247
     * supports only reading.
248
     *</pre>
249
     *@exception UnsupportedOperationException
250
     */
251
    @NotImplemented
252
    public void setCellValue(RichTextString value) {
253
        throw new UnsupportedOperationException("Operation not supported.");
254
    }
255
256
    /**
257
     * <pre>
258
     * Not supported right now, as StreamedWorkbook
259
     * supports only reading.
260
     *</pre>
261
     *@exception UnsupportedOperationException
262
     */
263
    @NotImplemented
264
    public void setCellValue(String value) {
265
        throw new UnsupportedOperationException("Operation not supported."); 
266
    }
267
268
    /**
269
     * <pre>
270
     * Not supported right now, as StreamedWorkbook
271
     * supports only reading.
272
     *</pre>
273
     *@exception UnsupportedOperationException
274
     */
275
    @NotImplemented
276
    public void setCellFormula(String formula) throws FormulaParseException {
277
        throw new UnsupportedOperationException("Operation not supported.");
278
    }
279
280
    /**
281
     *  <pre>
282
     * Not supported due to memory foot print.
283
     *  </pre>
284
     *  @exception UnsupportedOperationException
285
     */
286
    @NotImplemented
287
    public String getCellFormula() {
288
        throw new UnsupportedOperationException("Not implememted yet.");
289
    }
290
291
    /**
292
     *  <pre>
293
     * Not supported due to memory foot print.
294
     *  </pre>
295
     *  @exception UnsupportedOperationException
296
     */
297
    @NotImplemented
298
    public double getNumericCellValue() {
299
        throw new UnsupportedOperationException("Operation not supported.");
300
    }
301
302
    /**
303
     *  <pre>
304
     * Not supported due to memory foot print.
305
     *  </pre>
306
     *  @exception UnsupportedOperationException
307
     */
308
    @NotImplemented
309
    public Date getDateCellValue() {
310
        throw new UnsupportedOperationException("Operation not supported.");
311
    }
312
313
    /**
314
     *  <pre>
315
     * Will be supported in future.
316
     *  </pre>
317
     *  @exception UnsupportedOperationException
318
     */
319
    @NotImplemented
320
    public RichTextString getRichStringCellValue() {
321
        throw new UnsupportedOperationException("Not implememted yet.");
322
    }
323
324
    /**
325
     *  <pre>
326
     *  Returns the String value of cell content
327
     *  </pre>
328
     *  @return String, representing the value of cell
329
     */
330
    public String getStringCellValue() {
331
        return value;
332
    }
333
334
    /**
335
     * <pre>
336
     * Not supported right now, as StreamedWorkbook
337
     * supports only reading.
338
     *</pre>
339
     *@exception UnsupportedOperationException
340
     * 
341
     */
342
    @NotImplemented
343
    public void setCellValue(boolean value) {
344
        throw new UnsupportedOperationException("Operation not supported.");
345
    }
346
347
    /**
348
     * <pre>
349
     * Not supported right now, as StreamedWorkbook
350
     * supports only reading.
351
     *</pre>
352
     * @exception UnsupportedOperationException
353
     */
354
    @NotImplemented
355
    public void setCellErrorValue(byte value) {
356
        throw new UnsupportedOperationException("Operation not supported.");
357
    }
358
359
    /**
360
     *  <pre>
361
     * Not supported due to memory foot print.
362
     *  </pre>
363
     *  @exception UnsupportedOperationException
364
     */
365
    @NotImplemented
366
    public boolean getBooleanCellValue() {
367
        throw new UnsupportedOperationException("Operation not supported.");
368
    }
369
370
    /**
371
     *  <pre>
372
     * Will be supported in future.
373
     *  </pre>
374
     *  @exception UnsupportedOperationException
375
     */
376
    @NotImplemented
377
    public byte getErrorCellValue() {
378
        throw new UnsupportedOperationException("Operation not supported.");
379
    }
380
381
    /**
382
     * <pre>
383
     * Not supported right now, as StreamedWorkbook
384
     * supports only reading.
385
     *</pre>
386
     * @exception UnsupportedOperationException
387
     */
388
    @NotImplemented
389
    public void setCellStyle(CellStyle style) {
390
        throw new UnsupportedOperationException("Operation not supported.");
391
    }
392
393
    /**
394
     *  <pre>
395
     * Will be supported in future.
396
     *  </pre>
397
     *  @exception UnsupportedOperationException
398
     */
399
    @NotImplemented
400
    public CellStyle getCellStyle() {
401
        throw new UnsupportedOperationException("Operation not supported.");
402
    }
403
404
    /**
405
     * <pre>
406
     * Not supported right now, as StreamedWorkbook
407
     * supports only reading.
408
     *</pre>
409
     * @exception UnsupportedOperationException
410
     */
411
    @NotImplemented
412
    public void setAsActiveCell() {
413
        throw new UnsupportedOperationException("Operation not supported.");
414
    }
415
416
    /**
417
     *  <pre>
418
     * Will be supported in future.
419
     *  </pre>
420
     *  @exception UnsupportedOperationException
421
     */
422
    @NotImplemented
423
    public CellAddress getAddress() {
424
        throw new UnsupportedOperationException("Not implememted yet.");
425
    }
426
    /**
427
     * <pre>
428
     * Not supported right now, as StreamedWorkbook
429
     * supports only reading.
430
     *</pre>
431
     *@exception UnsupportedOperationException
432
     * 
433
     */
434
    @NotImplemented
435
    public void setCellComment(Comment comment) {
436
        throw new UnsupportedOperationException("Operation not supported.");
437
    }
438
439
    /**
440
     *  <pre>
441
     * Not supported due to memory footprint
442
     *  </pre>
443
     *  @exception UnsupportedOperationException
444
     */
445
    @NotImplemented
446
    public Comment getCellComment() {
447
        throw new UnsupportedOperationException("Operation not supported.");
448
    }
449
450
    /**
451
     * <pre>
452
     * Not supported right now, as StreamedWorkbook
453
     * supports only reading.
454
     *</pre>
455
     * @exception UnsupportedOperationException
456
     */
457
    @NotImplemented
458
    public void removeCellComment() {
459
        throw new UnsupportedOperationException("Operation not supported.");
460
    }
461
462
    /**
463
     *  <pre>
464
     * Will be supported in future.
465
     *  </pre>
466
     *  @exception UnsupportedOperationException
467
     */
468
    @NotImplemented
469
    public Hyperlink getHyperlink() {
470
        throw new UnsupportedOperationException("Operation not supported.");
471
    }
472
473
    /**
474
     * <pre>
475
     * Not supported right now, as StreamedWorkbook
476
     * supports only reading.
477
     *</pre>
478
     *@exception UnsupportedOperationException
479
     * 
480
     */
481
    @NotImplemented
482
    public void setHyperlink(Hyperlink link) {
483
        throw new UnsupportedOperationException("Operation not supported.");
484
    }
485
486
    /**
487
     * <pre>
488
     * Not supported right now, as StreamedWorkbook
489
     * supports only reading.
490
     *</pre>
491
     * @exception UnsupportedOperationException
492
     */
493
    @NotImplemented
494
    public void removeHyperlink() {
495
        throw new UnsupportedOperationException("Operation not supported.");
496
    }
497
498
    /**
499
     *  <pre>
500
     * Will be supported in future.
501
     *  </pre>
502
     *  @exception UnsupportedOperationException
503
     */
504
    @NotImplemented
505
    public CellRangeAddress getArrayFormulaRange() {
506
        throw new UnsupportedOperationException("Operation not supported.");
507
    }
508
509
    /**
510
     *  <pre>
511
     * Will be supported in future.
512
     *  </pre>
513
     *  @exception UnsupportedOperationException
514
     */
515
    @NotImplemented
516
    public boolean isPartOfArrayFormulaGroup() {
517
        throw new UnsupportedOperationException("Operation not supported.");
518
    }
519
520
    /*@Override
521
    protected void finalize() throws Throwable {
522
        super.finalize();
523
        value = null;
524
    }*/
525
    
526
    
527
    
528
}
(-)a/src/ooxml/java/org/apache/poi/xssf/streaming/reader/StreamedRow.java (+402 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.streaming.reader;
18
19
import java.util.ArrayList;
20
import java.util.Iterator;
21
import java.util.List;
22
23
import org.apache.poi.ss.usermodel.Cell;
24
import org.apache.poi.ss.usermodel.CellStyle;
25
import org.apache.poi.ss.usermodel.CellType;
26
import org.apache.poi.ss.usermodel.Row;
27
import org.apache.poi.ss.usermodel.Sheet;
28
import org.apache.poi.util.NotImplemented;
29
30
31
/**
32
 * Represents an excel row.
33
 * Supports only minimal functionality in order to reduce memory consumption.
34
 *
35
 */
36
public class StreamedRow implements Row{
37
    private List<StreamedCell> cells;
38
    private int rowNumber;
39
40
    public StreamedRow(int rowNumber) {
41
        this.rowNumber = rowNumber;
42
    }
43
44
    /**
45
     * <pre>
46
     * Used to get cells of a Row
47
     * </pre>
48
     * @return Iterator<Cell>
49
     */
50
    public Iterator<StreamedCell> getCellIterator() {
51
        if (cells == null) {
52
            cells = new ArrayList<StreamedCell>();
53
        }
54
        return cells.iterator();
55
    }
56
    
57
    /**
58
     * <pre>
59
     *  Returns the row number
60
     * </pre>
61
     * @return int
62
     */
63
    public int getRowNum() {
64
        return rowNumber;
65
    }
66
67
    public void setRowNum(int rowNumber) {
68
        this.rowNumber = rowNumber;
69
    }
70
71
    /**
72
     * <pre>
73
     * Returns String representation of row.
74
     * o/p format[Row Number:<row num> --> <col_1>|<col_2>|.....|<col_n>]
75
     * </pre>
76
     * @return String
77
     */
78
    public String toString() {
79
        StringBuffer sb = new StringBuffer(250);
80
        sb.append("Row Number:").append(rowNumber);
81
        sb.append(" --> ");
82
        if (cells != null) {
83
            for (StreamedCell cell : cells) {
84
                sb.append(cell.toString());
85
                sb.append(" | ");
86
            }
87
        }
88
89
        return sb.toString();
90
    }
91
92
/*  @Override
93
    protected void finalize() throws Throwable {
94
        super.finalize();
95
        if (cells != null) {
96
            cells.clear();
97
            cells = null;
98
        }
99
    }*/
100
101
    /**
102
     * <pre>
103
     * Retuns the List of Cells contained in the row.
104
     * </pre>
105
     * @return List<StreamedCell>
106
     */
107
    public List<StreamedCell> getCells() {
108
        if (cells == null) {
109
            cells = new ArrayList<StreamedCell>();
110
        }
111
        return cells;
112
    }
113
114
/**
115
 * <pre>
116
 * Will not be supported. Use getCellIterator() instead
117
 * </pre>   
118
 * @exception UnsupportedOperationException
119
 */
120
@NotImplemented
121
public Iterator<Cell> iterator() {
122
    throw new UnsupportedOperationException("Operation not supported. Use getCellIterator() instead.");
123
}
124
125
/**
126
 * <pre>
127
 * Not supported right now, as StreamedWorkbook
128
 * supports only reading.
129
 * </pre>
130
 * @exception UnsupportedOperationException
131
 * 
132
 */
133
@NotImplemented
134
public Cell createCell(int column) {
135
    throw new UnsupportedOperationException("Operation not supported.");
136
}
137
138
/**
139
 * <pre>
140
 * Not supported right now, as StreamedWorkbook
141
 * supports only reading.
142
 * </pre>
143
 * @exception UnsupportedOperationException
144
 */
145
@NotImplemented
146
public Cell createCell(int column, int type) {
147
    throw new UnsupportedOperationException("Operation not supported.");
148
}
149
150
/**
151
 * <pre>
152
 * Not supported right now, as StreamedWorkbook
153
 * supports only reading.
154
 * </pre>
155
 * @exception UnsupportedOperationException
156
 */
157
@NotImplemented
158
public Cell createCell(int column, CellType type) {
159
    throw new UnsupportedOperationException("Operation not supported.");
160
}
161
162
/**
163
 * <pre>
164
 * Not supported right now, as StreamedWorkbook
165
 * supports only reading.
166
 * </pre>
167
 * @exception UnsupportedOperationException
168
 */
169
@NotImplemented
170
public void removeCell(Cell cell) {  
171
    throw new UnsupportedOperationException("Operation not supported.");
172
}
173
174
/**
175
 * <pre>
176
 *  Returns the cell on specified cell number
177
 * </pre>
178
 * @return Cell
179
 */
180
public Cell getCell(int cellnum) {
181
    StreamedCell cell = null;
182
    
183
    if(cells != null){
184
        cell = cells.get(cellnum);
185
    }
186
    
187
    return cell;
188
}
189
190
/**
191
 *  <pre>
192
 * Will be supported in future.
193
 *  </pre>
194
 *  @exception UnsupportedOperationException
195
 */
196
public Cell getCell(int cellnum, MissingCellPolicy policy) {
197
/*    StreamedCell cell = null;
198
    
199
    if(cells != null){
200
        cell = cells.get(cellnum);
201
    }
202
    
203
    switch(policy){
204
        case RETURN_NULL_AND_BLANK:
205
            return cell;
206
        case RETURN_BLANK_AS_NULL:
207
            boolean isBlank = (cell != null && cell.getCellTypeEnum() == CellType.BLANK);
208
            return (isBlank) ? null : cell;
209
        case CREATE_NULL_AS_BLANK:
210
            return (cell == null) ? createCell(cellnum, CellType.BLANK) : cell;
211
        default:
212
            throw new IllegalArgumentException("Illegal policy " + policy + " (" + policy.id + ")");
213
    }*/
214
    throw new UnsupportedOperationException("Not implememted yet.");
215
}
216
217
/**
218
 * <pre>
219
 * Get the number of the first cell contained in this row.
220
 * </pre>
221
 *
222
 * @return short representing the first logical cell in the row,
223
 *  or -1 if the row does not contain any cells.
224
 */
225
public short getFirstCellNum() {
226
    short firstCellNumber = -1;
227
    
228
    if(cells != null && cells.size() > 0){
229
       firstCellNumber = (short)cells.get(0).getCellNumber();
230
    }
231
    
232
    return firstCellNumber;
233
}
234
235
/**
236
 * <pre>
237
 * Gets the index of the last cell contained in this row <b>PLUS ONE</b>.
238
 * </pre>
239
 *
240
 * @return short representing the last logical cell in the row,
241
 *  or -1 if the row does not contain any cells.
242
 */
243
public short getLastCellNum() {
244
    short lastCellNumber = -1;
245
    
246
    if(cells != null && cells.size() > 0){
247
        lastCellNumber = (short)(cells.get((cells.size()-1)).getCellNumber()+1);
248
    }
249
    
250
    return lastCellNumber;
251
}
252
253
/**
254
 * <pre>
255
 * Gets the number of defined cells (NOT number of cells in the actual row!).
256
 * That is to say if only columns 0,4,5 have values then there would be 3.
257
 * </pre>
258
 * @return int representing the number of defined cells in the row.
259
 */
260
public int getPhysicalNumberOfCells() {
261
    if(cells != null)return cells.size();
262
    else return 0;
263
}
264
265
/**
266
 * <pre>
267
 * Not supported right now, as StreamedWorkbook
268
 * supports only reading.
269
 * </pre>
270
 * @exception UnsupportedOperationException
271
 */
272
@NotImplemented
273
public void setHeight(short height) {  
274
    throw new UnsupportedOperationException("Operation not supported.");
275
}
276
277
/**
278
 * <pre>
279
 * Not supported right now, as StreamedWorkbook
280
 * supports only reading.
281
 * </pre>
282
 * @exception UnsupportedOperationException
283
 */
284
@NotImplemented
285
public void setZeroHeight(boolean zHeight) {
286
    throw new UnsupportedOperationException("Operation not supported.");
287
}
288
289
/**
290
 *  <pre>
291
 * Will be supported in future.
292
 *  </pre>
293
 *  @exception UnsupportedOperationException
294
 */
295
@NotImplemented
296
public boolean getZeroHeight() {
297
    throw new UnsupportedOperationException("Not implememted yet.");
298
}
299
300
/**
301
 * <pre>
302
 * Not supported right now, as StreamedWorkbook
303
 * supports only reading.
304
 * </pre>
305
 * @exception UnsupportedOperationException
306
 */
307
@NotImplemented
308
public void setHeightInPoints(float height) {
309
    throw new UnsupportedOperationException("Operation not supported."); 
310
}
311
312
/**
313
 *  <pre>
314
 * Will be supported in future.
315
 *  </pre>
316
 *  @exception UnsupportedOperationException
317
 */
318
@NotImplemented
319
public short getHeight() {
320
    throw new UnsupportedOperationException("Not implememted yet.");
321
}
322
323
/**
324
 *  <pre>
325
 * Will be supported in future.
326
 *  </pre>
327
 *  @exception UnsupportedOperationException
328
 */
329
@NotImplemented
330
public float getHeightInPoints() {
331
    throw new UnsupportedOperationException("Not implememted yet.");
332
}
333
334
/**
335
 *  <pre>
336
 * Will be supported in future.
337
 *  </pre>
338
 *  @exception UnsupportedOperationException
339
 */
340
@NotImplemented
341
public boolean isFormatted() {
342
    throw new UnsupportedOperationException("Not implememted yet.");
343
}
344
345
/**
346
 *  <pre>
347
 * Will be supported in future.
348
 *  </pre>
349
 *  @exception UnsupportedOperationException
350
 */
351
@NotImplemented
352
public CellStyle getRowStyle() {
353
    throw new UnsupportedOperationException("Not implememted yet.");
354
}
355
356
/**
357
 * <pre>
358
 * Not supported right now, as StreamedWorkbook
359
 * supports only reading.
360
 * </pre>
361
 * @exception UnsupportedOperationException
362
 */
363
@NotImplemented
364
public void setRowStyle(CellStyle style) {
365
    throw new UnsupportedOperationException("Operation not supported."); 
366
}
367
368
/**
369
 * <pre>
370
 * Not supported right now. Use getCellIterator instead
371
 * </pre>
372
 * @exception UnsupportedOperationException
373
 */
374
@NotImplemented
375
public Iterator<Cell> cellIterator() {
376
    throw new UnsupportedOperationException("Operation not supported.Use getCellIterator instead."); 
377
}
378
379
/**
380
 *  <pre>
381
 * Will be supported in future.
382
 *  </pre>
383
 *  @exception UnsupportedOperationException
384
 */
385
@NotImplemented
386
public Sheet getSheet() {
387
    throw new UnsupportedOperationException("Operation not supported."); 
388
}
389
390
/**
391
 *  <pre>
392
 * Will be supported in future.
393
 *  </pre>
394
 *  @exception UnsupportedOperationException
395
 */
396
@NotImplemented
397
public int getOutlineLevel() {
398
    throw new UnsupportedOperationException("Not implememted yet.");
399
}
400
401
402
}
(-)a/src/ooxml/java/org/apache/poi/xssf/streaming/reader/StreamedSheet.java (+1645 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.streaming.reader;
18
19
import java.util.ArrayList;
20
import java.util.Collection;
21
import java.util.Iterator;
22
import java.util.List;
23
import java.util.Map;
24
25
import javax.xml.stream.XMLEventReader;
26
import javax.xml.stream.XMLStreamException;
27
import javax.xml.stream.events.XMLEvent;
28
29
import org.apache.poi.ss.usermodel.AutoFilter;
30
import org.apache.poi.ss.usermodel.Cell;
31
import org.apache.poi.ss.usermodel.CellRange;
32
import org.apache.poi.ss.usermodel.CellStyle;
33
import org.apache.poi.ss.usermodel.Comment;
34
import org.apache.poi.ss.usermodel.DataValidation;
35
import org.apache.poi.ss.usermodel.DataValidationHelper;
36
import org.apache.poi.ss.usermodel.Drawing;
37
import org.apache.poi.ss.usermodel.Footer;
38
import org.apache.poi.ss.usermodel.Header;
39
import org.apache.poi.ss.usermodel.Hyperlink;
40
import org.apache.poi.ss.usermodel.PrintSetup;
41
import org.apache.poi.ss.usermodel.Row;
42
import org.apache.poi.ss.usermodel.Sheet;
43
import org.apache.poi.ss.usermodel.SheetConditionalFormatting;
44
import org.apache.poi.ss.usermodel.Workbook;
45
import org.apache.poi.ss.util.CellAddress;
46
import org.apache.poi.ss.util.CellRangeAddress;
47
import org.apache.poi.ss.util.PaneInformation;
48
import org.apache.poi.util.NotImplemented;
49
import org.apache.poi.xssf.model.SharedStringsTable;
50
import org.apache.poi.xssf.model.StylesTable;
51
52
/**
53
 * Represents an excel sheet.
54
 * StreamedSheet currently supports only the minimal functionalities as 
55
 *  additional features requires caching of sheet data, which consumes memory. 
56
 *
57
 */
58
public class StreamedSheet implements Sheet{
59
    private XMLEventReader xmlParser;
60
    private SharedStringsTable sharedStringsTable;
61
    private StylesTable stylesTable;
62
    private int numberOfColumns;
63
    private int sheetNumber;
64
    private String sheetName;
65
    private StreamedSheetEventHandler eventHandler = null;
66
    
67
    /**
68
     * <pre>
69
     * Fetch all rows from the excel.
70
     * </pre>
71
     * 
72
     * This method consumes only less memory, but it is 
73
     * advisable to use it only for small excel files, since 
74
     * it will fetch all rows in a single call.
75
     * 
76
     * @return Iterator<Row>
77
     * @throws XMLStreamException
78
     */
79
    public Iterator<StreamedRow> getAllRows() throws XMLStreamException{
80
        return getAllRows(this, sharedStringsTable, stylesTable);
81
    }
82
    
83
    /**
84
     * <pre>
85
     * Used to fetch N number of rows.
86
     * </pre>
87
     * 
88
     * Recommended method to reduce memory utilization.
89
     * It allows to read big excel files in batch.
90
     * This gives control to the user to process the records already fetched, 
91
     * before fetching next set of records.
92
     * After reading N records, invoke the same method with number of rows to be
93
     * fetched to get the next set of rows.
94
     * <br>
95
     * 
96
     * *********************Usage****************************
97
     * Iterator<StreamedRow> rows = sheet.getNRows(1);
98
     * <br>
99
     * while(rows.hasNext()){ //read the first 1 row
100
     * <br>
101
     *     StreamedRow row = rows.next();
102
     * <br>
103
     * }
104
     *  <br>
105
     * rows = sheet.getNRows(10);
106
     *  <br>
107
     * while(rows.hasNext()){ //read the next 10 rows
108
     *  <br>
109
     *     StreamedRow row = rows.next();
110
     *  <br>
111
     * }
112
     * 
113
     * @param numberOfRows
114
     * @return Iterator<Row>
115
     * @throws XMLStreamException
116
     */
117
    public Iterator<StreamedRow> getNRows(int numberOfRows) throws XMLStreamException{
118
        return getNRows(this, eventHandler, numberOfRows);
119
    }
120
121
    public boolean hasMoreRows(){
122
        return xmlParser.hasNext();
123
    }
124
    
125
    
126
    public XMLEventReader getXmlParser() {
127
        return xmlParser;
128
    }
129
130
    public void setXmlParser(XMLEventReader xmlParser) {
131
        this.xmlParser = xmlParser;
132
    }
133
134
    public void setSharedStringsTable(SharedStringsTable sharedStringsTable) {
135
        this.sharedStringsTable = sharedStringsTable;
136
    }
137
138
    public void setStylesTable(StylesTable stylesTable) {
139
        this.stylesTable = stylesTable;
140
    }
141
    
142
    public void createEventHandler(){
143
        eventHandler = new StreamedSheetEventHandler(sharedStringsTable, stylesTable);
144
    }
145
146
147
    public int getNumberOfColumns() {
148
        return numberOfColumns;
149
    }
150
151
152
    public void setNumberOfColumns(int numberOfColumns) {
153
        this.numberOfColumns = numberOfColumns;
154
    }
155
156
157
    public int getSheetNumber() {
158
        return sheetNumber;
159
    }
160
161
162
    public void setSheetNumber(int sheetNumber) {
163
        this.sheetNumber = sheetNumber;
164
    }
165
166
/*  @Override
167
    protected void finalize() throws Throwable {
168
        super.finalize();
169
        
170
        xmlParser = null;
171
        sharedStringsTable = null;
172
        stylesTable = null;
173
        eventHandler = null;
174
        
175
    }*/
176
    
177
     /**
178
     * reads all data from sheet
179
     * @param xmlParser
180
     * @param sharedStringsTable
181
     * @param stylesTable
182
     * @return
183
     * @throws XMLStreamException 
184
     */
185
    private Iterator<StreamedRow> getAllRows(StreamedSheet sheet,
186
            SharedStringsTable sharedStringsTable, StylesTable stylesTable) throws XMLStreamException {
187
        List<StreamedRow> dataList = new ArrayList<StreamedRow>();
188
        StreamedSheetEventHandler eventHandler = new StreamedSheetEventHandler(sharedStringsTable, stylesTable);
189
        while(sheet.getXmlParser().hasNext()){
190
            XMLEvent event = sheet.getXmlParser().nextEvent();  
191
            eventHandler.handleEvent(event);
192
            if(eventHandler.isEndOfRow()){
193
                dataList.add(eventHandler.getRow());
194
                eventHandler.setEndOfRow(false);
195
            }
196
            sheet.setNumberOfColumns(eventHandler.getNumberOfColumns());
197
        }
198
        
199
        return dataList.iterator();
200
    }
201
    
202
    /**
203
     * Reads N Rows from excel
204
     * @param sheet
205
     * @param sharedStringsTable
206
     * @param stylesTable
207
     * @param numberOFRows
208
     * @return
209
     * @throws XMLStreamException
210
     */
211
    private Iterator<StreamedRow> getNRows(StreamedSheet sheet, StreamedSheetEventHandler eventHandler, int numberOfRows) 
212
            throws XMLStreamException {
213
        List<StreamedRow> dataList = new ArrayList<StreamedRow>();      
214
        while(sheet.getXmlParser().hasNext()){
215
            XMLEvent event = sheet.getXmlParser().nextEvent();  
216
            eventHandler.handleEvent(event);
217
            if(eventHandler.isEndOfRow()){
218
                dataList.add(eventHandler.getRow());
219
                eventHandler.setEndOfRow(false);
220
            }
221
            sheet.setNumberOfColumns(eventHandler.getNumberOfColumns());
222
            if(dataList.size() == numberOfRows){
223
                break;
224
            }
225
        }
226
        
227
        return dataList.iterator();
228
    }
229
230
    /**
231
     * Not supported. Refer getAllRows or getNRows
232
     * @exception UnsupportedOperationException
233
     */
234
    @NotImplemented
235
    public Iterator<Row> iterator() {
236
        throw new UnsupportedOperationException("Not supported. Refer getAllRows or getNRows");
237
    }
238
239
    /**
240
     * <pre>
241
     * Not supported right now, as StreamedWorkbook
242
     * supports only reading.
243
     * </pre>
244
     * @exception UnsupportedOperationException
245
     */
246
    @NotImplemented
247
    public Row createRow(int rownum) {
248
        throw new UnsupportedOperationException("Operation not supported.");
249
    }
250
251
    /**
252
     * <pre>
253
     * Not supported right now, as StreamedWorkbook
254
     * supports only reading.
255
     * </pre>
256
     * @exception UnsupportedOperationException
257
     */
258
    @NotImplemented
259
    public void removeRow(Row row) {
260
        throw new UnsupportedOperationException("Operation not supported.");
261
    }
262
263
    /**
264
     * <pre>
265
     *  Not supported due to memory footprint.
266
     * </pre>
267
     * @exception UnsupportedOperationException
268
     */
269
    @NotImplemented
270
    public Row getRow(int rownum) {
271
        throw new UnsupportedOperationException("Operation not supported.");
272
    }
273
274
    /**
275
     * <pre>
276
     *  Not supported due to memory footprint.
277
     * </pre>
278
     * @exception UnsupportedOperationException
279
     */
280
    @NotImplemented
281
    public int getPhysicalNumberOfRows() {
282
        throw new UnsupportedOperationException("Operation not supported.");
283
    }
284
285
    /**
286
     * <pre>
287
     * Will be supported in the future.
288
     * </pre>
289
     * @exception UnsupportedOperationException
290
     */
291
    @NotImplemented
292
    public int getFirstRowNum() {
293
        throw new UnsupportedOperationException("Not yet implemented.");
294
    }
295
296
    /**
297
     * <pre>
298
     *  Not supported due to memory footprint.
299
     * </pre>
300
     * @exception UnsupportedOperationException
301
     */
302
    @NotImplemented
303
    public int getLastRowNum() {
304
        throw new UnsupportedOperationException("Operation not supported.");
305
    }
306
307
    /**
308
     * <pre>
309
     * Not supported right now, as StreamedWorkbook
310
     * supports only reading.
311
     * </pre>
312
     * @exception UnsupportedOperationException
313
     * 
314
     */
315
    @NotImplemented
316
    public void setColumnHidden(int columnIndex, boolean hidden) { 
317
        throw new UnsupportedOperationException("Operation not supported.");
318
    }
319
320
    /**
321
     * <pre>
322
     *  Not supported due to memory footprint.
323
     * </pre>
324
     * @exception UnsupportedOperationException
325
     */
326
    @NotImplemented
327
    public boolean isColumnHidden(int columnIndex) {
328
        throw new UnsupportedOperationException("Operation not supported.");
329
    }
330
331
    /**
332
     * <pre>
333
     * Not supported right now, as StreamedWorkbook
334
     * supports only reading.
335
     * </pre>
336
     * @exception UnsupportedOperationException
337
     * 
338
     */
339
    @NotImplemented
340
    public void setRightToLeft(boolean value) {
341
        throw new UnsupportedOperationException("Operation not supported.");
342
    }
343
344
    /**
345
     * <pre>
346
     * Not supported right now, as StreamedWorkbook
347
     * supports only reading.
348
     * </pre>
349
     * @exception UnsupportedOperationException
350
     */
351
    @NotImplemented
352
    public boolean isRightToLeft() {
353
        throw new UnsupportedOperationException("Operation not supported.");
354
    }
355
356
    /**
357
     * <pre>
358
     * Not supported right now, as StreamedWorkbook
359
     * supports only reading.
360
     * </pre>
361
     * @exception UnsupportedOperationException
362
     */
363
    @NotImplemented
364
    public void setColumnWidth(int columnIndex, int width) {
365
        throw new UnsupportedOperationException("Operation not supported.");
366
    }
367
368
    /**
369
     *  <pre>
370
     * Not supported due to memory footprint.
371
     *  </pre>
372
     */
373
    @NotImplemented
374
    public int getColumnWidth(int columnIndex) {
375
        throw new UnsupportedOperationException("Operation not supported.");
376
    }
377
378
379
    /**
380
     *  <pre>
381
     * Not supported due to memory footprint.
382
     *  </pre>
383
     *  @exception UnsupportedOperationException
384
     */
385
    @NotImplemented
386
    public float getColumnWidthInPixels(int columnIndex) {
387
        throw new UnsupportedOperationException("Operation not supported.");
388
    }
389
390
    /**
391
     * <pre>
392
     * Not supported right now, as StreamedWorkbook
393
     * supports only reading.
394
     * </pre>
395
     * @exception UnsupportedOperationException
396
     */   
397
    @NotImplemented
398
    public void setDefaultColumnWidth(int width) {
399
        throw new UnsupportedOperationException("Operation not supported.");
400
    }
401
402
    /**
403
     *  <pre>
404
     * Not supported due to memory footprint.
405
     *  </pre>
406
     *  @exception UnsupportedOperationException
407
     */
408
    @NotImplemented
409
    public int getDefaultColumnWidth() {
410
        throw new UnsupportedOperationException("Operation not supported.");
411
    }
412
413
    /**
414
     *  <pre>
415
     * Not supported due to memory footprint.
416
     *  </pre>
417
     *  @exception UnsupportedOperationException
418
     */
419
    @NotImplemented
420
    public short getDefaultRowHeight() {
421
        throw new UnsupportedOperationException("Operation not supported.");
422
    }
423
424
    /**
425
     *  <pre>
426
     * Not supported due to memory footprint.
427
     *  </pre>
428
     *  @exception UnsupportedOperationException
429
     */
430
    @NotImplemented
431
    public float getDefaultRowHeightInPoints() {
432
        throw new UnsupportedOperationException("Operation not supported.");
433
    }
434
435
    /**
436
     * <pre>
437
     * Not supported right now, as StreamedWorkbook
438
     * supports only reading.
439
     * </pre>
440
     * @exception UnsupportedOperationException
441
     * 
442
     */  
443
    @NotImplemented
444
    public void setDefaultRowHeight(short height) {
445
        throw new UnsupportedOperationException("Operation not supported.");
446
    }
447
448
    /**
449
     * <pre>
450
     * Not supported right now, as StreamedWorkbook
451
     * supports only reading.
452
     * </pre>
453
     * @exception UnsupportedOperationException
454
     * 
455
     */   
456
    public void setDefaultRowHeightInPoints(float height) {
457
        throw new UnsupportedOperationException("Operation not supported.");
458
    }
459
460
    /**
461
     *  <pre>
462
     * Not supported due to memory footprint.
463
     *  </pre>
464
     *  @exception UnsupportedOperationException
465
     */
466
    @NotImplemented
467
    public CellStyle getColumnStyle(int column) {
468
        throw new UnsupportedOperationException("Operation not supported.");
469
    }
470
471
    /**
472
     * <pre>
473
     * Not supported right now, as StreamedWorkbook
474
     * supports only reading.
475
     * </pre>
476
     * @exception UnsupportedOperationException
477
     * 
478
     */   
479
    @NotImplemented
480
    public int addMergedRegion(CellRangeAddress region) {
481
        throw new UnsupportedOperationException("Operation not supported.");
482
    }
483
484
    /**
485
     * <pre>
486
     * Not supported right now, as StreamedWorkbook
487
     * supports only reading.
488
     * </pre>
489
     * @exception UnsupportedOperationException
490
     * 
491
     */  
492
    @NotImplemented
493
    public int addMergedRegionUnsafe(CellRangeAddress region) {
494
        throw new UnsupportedOperationException("Operation not supported.");
495
    }
496
497
    /**
498
     *  <pre>
499
     * Not supported due to memory footprint.
500
     *  </pre>
501
     *  @exception UnsupportedOperationException
502
     */
503
    @NotImplemented
504
    public void validateMergedRegions() {  
505
        throw new UnsupportedOperationException("Operation not supported.");
506
    }
507
508
    /**
509
     * <pre>
510
     * Not supported right now, as StreamedWorkbook
511
     * supports only reading.
512
     * </pre>
513
     * @exception UnsupportedOperationException
514
     * 
515
     */
516
    @NotImplemented
517
    public void setVerticallyCenter(boolean value) {
518
        throw new UnsupportedOperationException("Operation not supported.");
519
    }
520
521
    /**
522
     * <pre>
523
     * Not supported right now, as StreamedWorkbook
524
     * supports only reading.
525
     * </pre>
526
     * @exception UnsupportedOperationException
527
     */ 
528
    @NotImplemented
529
    public void setHorizontallyCenter(boolean value) { 
530
        throw new UnsupportedOperationException("Operation not supported.");
531
    }
532
533
    /**
534
     *  <pre>
535
     * Not supported due to memory footprint.
536
     *  </pre>
537
     *  @exception UnsupportedOperationException
538
     */
539
    @NotImplemented
540
    public boolean getHorizontallyCenter() {
541
        throw new UnsupportedOperationException("Operation not supported.");
542
    }
543
544
    /**
545
     *  <pre>
546
     * Not supported due to memory footprint.
547
     *  </pre>
548
     *  @exception UnsupportedOperationException
549
     */
550
    @NotImplemented
551
    public boolean getVerticallyCenter() {
552
        throw new UnsupportedOperationException("Operation not supported.");
553
    }
554
555
    /**
556
     * <pre>
557
     * Not supported right now, as StreamedWorkbook
558
     * supports only reading.
559
     * </pre>
560
     * @exception UnsupportedOperationException
561
     * 
562
     */ 
563
    @NotImplemented
564
    public void removeMergedRegion(int index) {
565
        throw new UnsupportedOperationException("Operation not supported.");
566
    }
567
568
    /**
569
     * <pre>
570
     * Not supported right now, as StreamedWorkbook
571
     * supports only reading.
572
     * </pre>
573
     * @exception UnsupportedOperationException
574
     * 
575
     */ 
576
    @NotImplemented
577
    public void removeMergedRegions(Collection<Integer> indices) {
578
        throw new UnsupportedOperationException("Operation not supported.");
579
    }
580
581
    /**
582
     *  <pre>
583
     * Not supported due to memory footprint.
584
     *  </pre>
585
     *  @exception UnsupportedOperationException
586
     */
587
    @NotImplemented
588
    public int getNumMergedRegions() {
589
        throw new UnsupportedOperationException("Operation not supported.");
590
    }
591
592
    /**
593
     *  <pre>
594
     * Not supported due to memory footprint.
595
     *  </pre>
596
     *  @exception UnsupportedOperationException
597
     */
598
    public CellRangeAddress getMergedRegion(int index) {
599
        throw new UnsupportedOperationException("Operation not supported.");
600
    }
601
602
    /**
603
     *  <pre>
604
     * Not supported due to memory footprint.
605
     *  </pre>
606
     *  @exception UnsupportedOperationException
607
     */
608
    @NotImplemented
609
    public List<CellRangeAddress> getMergedRegions() {
610
        throw new UnsupportedOperationException("Operation not supported.");
611
    }
612
613
    /**
614
     * <pre>
615
     * Not supported. Use getAllRows or getNRows
616
     * </pre>
617
     * @exception UnsupportedOperationException
618
     */
619
    @NotImplemented
620
    public Iterator<Row> rowIterator() {
621
        throw new UnsupportedOperationException("Operation not supported.Use getAllRows or getNRows.");
622
    }
623
624
    /**
625
     * <pre>
626
     * Not supported right now, as StreamedWorkbook
627
     * supports only reading.
628
     * </pre>
629
     * @exception UnsupportedOperationException
630
     * 
631
     */ 
632
    public void setForceFormulaRecalculation(boolean value) {
633
        throw new UnsupportedOperationException("Operation not supported.");
634
    }
635
636
    /**
637
     *  <pre>
638
     * Not supported due to memory footprint.
639
     *  </pre>
640
     *  @exception UnsupportedOperationException
641
     */
642
    @NotImplemented
643
    public boolean getForceFormulaRecalculation() {
644
        throw new UnsupportedOperationException("Operation not supported.");
645
    }
646
647
    /**
648
     * <pre>
649
     * Not supported right now, as StreamedWorkbook
650
     * supports only reading.
651
     * </pre>
652
     * @exception UnsupportedOperationException
653
     */ 
654
    @NotImplemented
655
    public void setAutobreaks(boolean value) {
656
        throw new UnsupportedOperationException("Operation not supported.");
657
    }
658
659
    /**
660
     * <pre>
661
     * Not supported right now, as StreamedWorkbook
662
     * supports only reading.
663
     * </pre>
664
     * @exception UnsupportedOperationException
665
     */ 
666
    @NotImplemented
667
    public void setDisplayGuts(boolean value) {
668
        throw new UnsupportedOperationException("Operation not supported.");
669
    }
670
671
    /**
672
     *  <pre>
673
     * Not supported right now, as StreamedWorkbook
674
     *  supports only reading.
675
     *  </pre>
676
     *  @exception UnsupportedOperationException
677
     */
678
    @NotImplemented
679
    public void setDisplayZeros(boolean value) {
680
        throw new UnsupportedOperationException("Operation not supported.");
681
    }
682
683
    /**
684
     *  <pre>
685
     * Not supported due to memory footprint.
686
     *  </pre>
687
     *  @exception UnsupportedOperationException
688
     */
689
    @NotImplemented
690
    public boolean isDisplayZeros() {
691
        throw new UnsupportedOperationException("Operation not supported.");
692
    }
693
694
    /**
695
     * <pre>
696
     * Not supported right now, as StreamedWorkbook
697
     * supports only reading.
698
     * </pre>
699
     * @exception UnsupportedOperationException
700
     */ 
701
    @NotImplemented
702
    public void setFitToPage(boolean value) { 
703
        throw new UnsupportedOperationException("Operation not supported.");
704
    }
705
706
    /**
707
     * <pre>
708
     * Not supported right now, as StreamedWorkbook
709
     * supports only reading.
710
     * </pre>
711
     * @exception UnsupportedOperationException
712
     */ 
713
    @NotImplemented
714
    public void setRowSumsBelow(boolean value) {  
715
        throw new UnsupportedOperationException("Operation not supported.");
716
    }
717
718
    /**
719
     * <pre>
720
     * Not supported right now, as StreamedWorkbook
721
     * supports only reading.
722
     * </pre>
723
     * @exception UnsupportedOperationException
724
     */ 
725
    @NotImplemented
726
    public void setRowSumsRight(boolean value) { 
727
        throw new UnsupportedOperationException("Operation not supported.");
728
    }
729
730
    /**
731
     *  <pre>
732
     * Not supported due to memory footprint.
733
     *  </pre>
734
     *  @exception UnsupportedOperationException
735
     */
736
    @NotImplemented
737
    public boolean getAutobreaks() {
738
        throw new UnsupportedOperationException("Operation not supported.");
739
    }
740
741
    /**
742
     *  <pre>
743
     * Not supported due to memory footprint..
744
     *  </pre>
745
     */
746
    @NotImplemented
747
    public boolean getDisplayGuts() {
748
        throw new UnsupportedOperationException("Operation not supported.");
749
    }
750
751
    /**
752
     *  <pre>
753
     * Not supported due to memory footprint.
754
     *  </pre>
755
     *  @exception UnsupportedOperationException
756
     */
757
    @NotImplemented
758
    public boolean getFitToPage() {
759
        throw new UnsupportedOperationException("Operation not supported.");
760
    }
761
762
    /**
763
     *  <pre>
764
     * Not supported due to memory footprint.
765
     *  </pre>
766
     *  @exception UnsupportedOperationException
767
     */
768
    @NotImplemented
769
    public boolean getRowSumsBelow() {
770
        throw new UnsupportedOperationException("Operation not supported.");
771
    }
772
773
    /**
774
     *  <pre>
775
     * Not supported due to memory footprint.
776
     *  </pre>
777
     *  @exception UnsupportedOperationException
778
     */
779
    @NotImplemented
780
    public boolean getRowSumsRight() {
781
        throw new UnsupportedOperationException("Operation not supported.");
782
    }
783
784
    /**
785
     *  <pre>
786
     * Not supported due to memory footprint.
787
     *  </pre>
788
     *  @exception UnsupportedOperationException
789
     */
790
    @NotImplemented
791
    public boolean isPrintGridlines() {
792
        throw new UnsupportedOperationException("Operation not supported.");
793
    }
794
795
    /**
796
     * <pre>
797
     * Not supported right now, as StreamedWorkbook
798
     * supports only reading.
799
     * </pre>
800
     * @exception UnsupportedOperationException
801
     */ 
802
    @NotImplemented
803
    public void setPrintGridlines(boolean show) {
804
        throw new UnsupportedOperationException("Operation not supported.");
805
    }
806
807
    /**
808
     *  <pre>
809
     * Not supported due to memory footprint.
810
     *  </pre>
811
     *  @exception UnsupportedOperationException
812
     */
813
    @NotImplemented
814
    public boolean isPrintRowAndColumnHeadings() {
815
        throw new UnsupportedOperationException("Operation not supported.");
816
    }
817
818
    /**
819
     * <pre>
820
     * Not supported right now, as StreamedWorkbook
821
     * supports only reading.
822
     * </pre>
823
     * @exception UnsupportedOperationException
824
     * 
825
     */ 
826
    @NotImplemented
827
    public void setPrintRowAndColumnHeadings(boolean show) {
828
        throw new UnsupportedOperationException("Operation not supported.");
829
    }
830
831
    /**
832
     *  <pre>
833
     * Not supported due to memory footprint.
834
     *  </pre>
835
     *  @exception UnsupportedOperationException
836
     */
837
    @NotImplemented
838
    public PrintSetup getPrintSetup() {
839
        throw new UnsupportedOperationException("Operation not supported.");
840
    }
841
842
    /**
843
     *  <pre>
844
     * Will be supported in future.
845
     *  </pre>
846
     *  @exception UnsupportedOperationException
847
     */
848
    @NotImplemented
849
    public Header getHeader() {
850
        // <TO DO>
851
        throw new UnsupportedOperationException("Not implemented yet.");
852
    }
853
854
    /**
855
     *  <pre>
856
     * Not supported due to memory footprint.
857
     *  </pre>
858
     *  @exception UnsupportedOperationException
859
     */
860
    @NotImplemented
861
    public Footer getFooter() {
862
        throw new UnsupportedOperationException("Operation not supported.");
863
    }
864
865
    /**
866
     * <pre>
867
     * Not supported right now, as StreamedWorkbook
868
     * supports only reading.
869
     * </pre>
870
     * @exception UnsupportedOperationException
871
     */ 
872
    @NotImplemented
873
    public void setSelected(boolean value) {
874
        throw new UnsupportedOperationException("Operation not supported.");
875
    }
876
877
    /**
878
     *  <pre>
879
     * Not supported due to memory footprint.
880
     *  </pre>
881
     *  @exception UnsupportedOperationException
882
     */
883
    @NotImplemented
884
    public double getMargin(short margin) {
885
        throw new UnsupportedOperationException("Operation not supported.");
886
    }
887
888
    /**
889
     * <pre>
890
     * Not supported right now, as StreamedWorkbook
891
     * supports only reading.
892
     * </pre>
893
     * @exception UnsupportedOperationException
894
     * 
895
     */ 
896
    @NotImplemented
897
    public void setMargin(short margin, double size) {
898
        throw new UnsupportedOperationException("Operation not supported.");
899
    }
900
    
901
    /**
902
     *  <pre>
903
     * Not supported due to memory footprint.
904
     *  </pre>
905
     *  @exception UnsupportedOperationException
906
     */
907
    @NotImplemented
908
    public boolean getProtect() {
909
        throw new UnsupportedOperationException("Operation not supported.");
910
    }
911
912
    /**
913
     * <pre>
914
     * Not supported right now, as StreamedWorkbook
915
     * supports only reading.
916
     * </pre>
917
     * @exception UnsupportedOperationException
918
     * 
919
     */ 
920
    @NotImplemented
921
    public void protectSheet(String password) {
922
        throw new UnsupportedOperationException("Operation not supported.");
923
    }
924
925
    /**
926
     *  <pre>
927
     * Not supported due to memory footprint.
928
     *  </pre>
929
     *  @exception UnsupportedOperationException
930
     */
931
    @NotImplemented
932
    public boolean getScenarioProtect() {
933
        throw new UnsupportedOperationException("Operation not supported.");
934
    }
935
936
    /**
937
     * <pre>
938
     * Not supported right now, as StreamedWorkbook
939
     * supports only reading.
940
     * </pre>
941
     * @exception UnsupportedOperationException
942
     * 
943
     */ 
944
    @NotImplemented
945
    public void setZoom(int numerator, int denominator) {  
946
        throw new UnsupportedOperationException("Operation not supported.");
947
    }
948
949
    /**
950
     * <pre>
951
     * Not supported right now, as StreamedWorkbook
952
     * supports only reading.
953
     * </pre>
954
     * @exception UnsupportedOperationException
955
     * 
956
     */ 
957
    @NotImplemented
958
    public void setZoom(int scale) {
959
        throw new UnsupportedOperationException("Operation not supported.");
960
    }
961
962
    /**
963
     *  <pre>
964
     * Will be supported in future.
965
     *  </pre>
966
     *  @exception UnsupportedOperationException
967
     */
968
    @NotImplemented
969
    public short getTopRow() {
970
        //<TO DO>
971
        throw new UnsupportedOperationException("Not implemented yet.");
972
    }
973
974
    /**
975
     *  <pre>
976
     * Will be supported in future.
977
     *  </pre>
978
     *  @exception UnsupportedOperationException
979
     */
980
    public short getLeftCol() {
981
        //<TO DO>
982
        throw new UnsupportedOperationException("Not implemented yet.");
983
    }
984
985
    /**
986
     *  <pre>
987
     * Not supported due to memory footprint.
988
     *  </pre>
989
     *  @exception UnsupportedOperationException
990
     */
991
    @NotImplemented
992
    public void showInPane(int toprow, int leftcol) {  
993
        throw new UnsupportedOperationException("Operation not supported.");    
994
    }
995
996
    /**
997
     * <pre>
998
     * Not supported right now, as StreamedWorkbook
999
     * supports only reading.
1000
     * </pre>
1001
     * @exception UnsupportedOperationException
1002
     * 
1003
     */ 
1004
    @NotImplemented
1005
    public void shiftRows(int startRow, int endRow, int n) {
1006
        throw new UnsupportedOperationException("Operation not supported.");    
1007
    }
1008
1009
    /**
1010
     * <pre>
1011
     * Not supported right now, as StreamedWorkbook
1012
     * supports only reading.
1013
     * </pre>
1014
     * @exception UnsupportedOperationException
1015
     * 
1016
     */ 
1017
    @NotImplemented
1018
    public void shiftRows(int startRow, int endRow, int n,
1019
            boolean copyRowHeight, boolean resetOriginalRowHeight) {
1020
        throw new UnsupportedOperationException("Operation not supported.");    
1021
    }
1022
1023
    /**
1024
     * <pre>
1025
     * Not supported right now, as StreamedWorkbook
1026
     * supports only reading.
1027
     * </pre>
1028
     * @exception UnsupportedOperationException
1029
     * 
1030
     */ 
1031
    @NotImplemented
1032
    public void createFreezePane(int colSplit, int rowSplit,
1033
            int leftmostColumn, int topRow) { 
1034
        throw new UnsupportedOperationException("Operation not supported.");    
1035
    }
1036
1037
    /**
1038
     * <pre>
1039
     * Not supported right now, as StreamedWorkbook
1040
     * supports only reading.
1041
     * </pre>
1042
     * @exception UnsupportedOperationException
1043
     */ 
1044
    @NotImplemented
1045
    public void createFreezePane(int colSplit, int rowSplit) { 
1046
        throw new UnsupportedOperationException("Operation not supported.");    
1047
    }
1048
1049
    /**
1050
     * <pre>
1051
     * Not supported right now, as StreamedWorkbook
1052
     * supports only reading.
1053
     * </pre>
1054
     * @exception UnsupportedOperationException
1055
     */ 
1056
    @NotImplemented
1057
    public void createSplitPane(int xSplitPos, int ySplitPos,
1058
            int leftmostColumn, int topRow, int activePane) { 
1059
        throw new UnsupportedOperationException("Operation not supported.");    
1060
    }
1061
1062
    /**
1063
     *  <pre>
1064
     * Not supported due to memory footprint.
1065
     *  </pre>
1066
     *  @exception UnsupportedOperationException
1067
     */
1068
    @NotImplemented
1069
    public PaneInformation getPaneInformation() {
1070
        throw new UnsupportedOperationException("Operation not supported.");    
1071
    }
1072
1073
    /**
1074
     * <pre>
1075
     * Not supported right now, as StreamedWorkbook
1076
     * supports only reading.
1077
     * </pre>
1078
     * @exception UnsupportedOperationException
1079
     */
1080
    @NotImplemented
1081
    public void setDisplayGridlines(boolean show) { 
1082
        throw new UnsupportedOperationException("Operation not supported.");    
1083
    }
1084
1085
    /**
1086
     *  <pre>
1087
     * Not supported due to memory footprint.
1088
     *  </pre>
1089
     *  @exception UnsupportedOperationException
1090
     */
1091
    @NotImplemented
1092
    public boolean isDisplayGridlines() {
1093
        throw new UnsupportedOperationException("Operation not supported.");    
1094
    }
1095
1096
    /**
1097
     * <pre>
1098
     * Not supported right now, as StreamedWorkbook
1099
     * supports only reading.
1100
     * </pre>
1101
     * @exception UnsupportedOperationException
1102
     * 
1103
     */
1104
    @NotImplemented
1105
    public void setDisplayFormulas(boolean show) {  
1106
        throw new UnsupportedOperationException("Operation not supported.");    
1107
    }
1108
1109
    /**
1110
     *  <pre>
1111
     * Not supported due to memory footprint.
1112
     *  </pre>
1113
     *  @exception UnsupportedOperationException
1114
     */
1115
    @NotImplemented
1116
    public boolean isDisplayFormulas() {
1117
        throw new UnsupportedOperationException("Operation not supported.");    
1118
    }
1119
1120
    /**
1121
     * <pre>
1122
     * Not supported right now, as StreamedWorkbook
1123
     * supports only reading.
1124
     * </pre>
1125
     * @exception UnsupportedOperationException
1126
     */
1127
    @NotImplemented
1128
    public void setDisplayRowColHeadings(boolean show) {
1129
        throw new UnsupportedOperationException("Operation not supported.");    
1130
    }
1131
1132
    /**
1133
     *  <pre>
1134
     * Not supported due to memory footprint.
1135
     *  </pre>
1136
     *  @exception UnsupportedOperationException
1137
     */
1138
    @NotImplemented
1139
    public boolean isDisplayRowColHeadings() {
1140
        throw new UnsupportedOperationException("Operation not supported.");    
1141
    }
1142
1143
    /**
1144
     * <pre>
1145
     * Not supported right now, as StreamedWorkbook
1146
     * supports only reading.
1147
     * </pre>
1148
     * @exception UnsupportedOperationException
1149
     */
1150
    @NotImplemented
1151
    public void setRowBreak(int row) {
1152
        throw new UnsupportedOperationException("Operation not supported.");    
1153
    }
1154
1155
    /**
1156
     *  <pre>
1157
     * Will be supported in future.
1158
     *  </pre>
1159
     *  @exception UnsupportedOperationException
1160
     */
1161
    @NotImplemented
1162
    public boolean isRowBroken(int row) {
1163
        throw new UnsupportedOperationException("Operation not supported.");    
1164
    }
1165
1166
    /**
1167
     * <pre>
1168
     * Not supported right now, as StreamedWorkbook
1169
     * supports only reading.
1170
     * </pre>
1171
     * @exception UnsupportedOperationException
1172
     */
1173
    @NotImplemented
1174
    public void removeRowBreak(int row) {
1175
        throw new UnsupportedOperationException("Operation not supported.");    
1176
    }
1177
1178
    /**
1179
     *  <pre>
1180
     * Not supported due to memory footprint.
1181
     *  </pre>
1182
     *  @exception UnsupportedOperationException
1183
     */
1184
    @NotImplemented
1185
    public int[] getRowBreaks() {
1186
        throw new UnsupportedOperationException("Operation not supported.");    
1187
    }
1188
1189
    /**
1190
     *  <pre>
1191
     * Not supported due to memory footprint.
1192
     *  </pre>
1193
     *  @exception UnsupportedOperationException
1194
     */
1195
    @NotImplemented
1196
    public int[] getColumnBreaks() {
1197
        throw new UnsupportedOperationException("Operation not supported.");    
1198
    }
1199
1200
    /**
1201
     * <pre>
1202
     * Not supported right now, as StreamedWorkbook
1203
     * supports only reading.
1204
     * </pre>
1205
     * @exception UnsupportedOperationException
1206
     */
1207
    @NotImplemented
1208
    public void setColumnBreak(int column) { 
1209
        throw new UnsupportedOperationException("Operation not supported.");    
1210
    }
1211
1212
    /**
1213
     *  <pre>
1214
     * Not supported due to memory footprint.
1215
     *  </pre>
1216
     *  @exception UnsupportedOperationException
1217
     */
1218
    @NotImplemented
1219
    public boolean isColumnBroken(int column) {
1220
        throw new UnsupportedOperationException("Operation not supported.");    
1221
    }
1222
1223
    /**
1224
     * <pre>
1225
     * Not supported right now, as StreamedWorkbook
1226
     * supports only reading.
1227
     * </pre>
1228
     * @exception UnsupportedOperationException
1229
     */
1230
    @NotImplemented
1231
    public void removeColumnBreak(int column) { 
1232
        throw new UnsupportedOperationException("Operation not supported.");    
1233
    }
1234
1235
    /**
1236
     * <pre>
1237
     * Not supported right now, as StreamedWorkbook
1238
     * supports only reading.
1239
     * </pre>
1240
     * @exception UnsupportedOperationException
1241
     */
1242
    @NotImplemented
1243
    public void setColumnGroupCollapsed(int columnNumber, boolean collapsed) {
1244
        throw new UnsupportedOperationException("Operation not supported.");    
1245
    }
1246
1247
    /**
1248
     * <pre>
1249
     * Not supported right now, as StreamedWorkbook
1250
     * supports only reading.
1251
     * </pre>
1252
     * @exception UnsupportedOperationException
1253
     */
1254
    @NotImplemented
1255
    public void groupColumn(int fromColumn, int toColumn) { 
1256
        throw new UnsupportedOperationException("Operation not supported.");    
1257
    }
1258
1259
    /**
1260
     * <pre>
1261
     * Not supported right now, as StreamedWorkbook
1262
     * supports only reading.
1263
     * </pre>
1264
     * @exception UnsupportedOperationException
1265
     */
1266
    @NotImplemented
1267
    public void ungroupColumn(int fromColumn, int toColumn) { 
1268
        throw new UnsupportedOperationException("Operation not supported.");    
1269
    }
1270
1271
    /**
1272
     * <pre>
1273
     * Not supported right now, as StreamedWorkbook
1274
     * supports only reading.
1275
     * </pre>
1276
     * @exception UnsupportedOperationException
1277
     */
1278
    @NotImplemented
1279
    public void groupRow(int fromRow, int toRow) { 
1280
        throw new UnsupportedOperationException("Operation not supported.");    
1281
    }
1282
1283
    /**
1284
     * <pre>
1285
     * Not supported right now, as StreamedWorkbook
1286
     * supports only reading.
1287
     * </pre>
1288
     * @exception UnsupportedOperationException
1289
     */
1290
    @NotImplemented
1291
    public void ungroupRow(int fromRow, int toRow) {
1292
        throw new UnsupportedOperationException("Operation not supported.");    
1293
    }
1294
1295
    /**
1296
     * <pre>
1297
     * Not supported right now, as StreamedWorkbook
1298
     * supports only reading.
1299
     * </pre>
1300
     * @exception UnsupportedOperationException
1301
     */
1302
    @NotImplemented
1303
    public void setRowGroupCollapsed(int row, boolean collapse) {
1304
        throw new UnsupportedOperationException("Operation not supported.");    
1305
    }
1306
1307
    /**
1308
     * <pre>
1309
     * Not supported right now, as StreamedWorkbook
1310
     * supports only reading.
1311
     * </pre>
1312
     * @exception UnsupportedOperationException
1313
     */
1314
    @NotImplemented
1315
    public void setDefaultColumnStyle(int column, CellStyle style) {
1316
        throw new UnsupportedOperationException("Operation not supported.");    
1317
    }
1318
1319
    /**
1320
     * <pre>
1321
     * Not supported right now, as StreamedWorkbook
1322
     * supports only reading.
1323
     * </pre>
1324
     * @exception UnsupportedOperationException
1325
     */
1326
    @NotImplemented
1327
    public void autoSizeColumn(int column) {
1328
        throw new UnsupportedOperationException("Operation not supported.");    
1329
    }
1330
1331
    /**
1332
     * <pre>
1333
     * Not supported right now, as StreamedWorkbook
1334
     * supports only reading.
1335
     * </pre>
1336
     * @exception UnsupportedOperationException
1337
     */
1338
    @NotImplemented
1339
    public void autoSizeColumn(int column, boolean useMergedCells) {
1340
        throw new UnsupportedOperationException("Operation not supported.");    
1341
    }
1342
1343
    /**
1344
     *  <pre>
1345
     * Not supported due to memory footprint.
1346
     *  </pre>
1347
     *  @exception UnsupportedOperationException
1348
     */
1349
    @NotImplemented
1350
    public Comment getCellComment(int row, int column) {
1351
        throw new UnsupportedOperationException("Operation not supported.");    
1352
    }
1353
1354
    /**
1355
     *  <pre>
1356
     * Not supported due to memory footprint.
1357
     *  </pre>
1358
     *  @exception UnsupportedOperationException
1359
     */
1360
    @NotImplemented
1361
    public Comment getCellComment(CellAddress ref) {
1362
        throw new UnsupportedOperationException("Operation not supported.");    
1363
    }
1364
1365
    /**
1366
     *  <pre>
1367
     * WNot supported due to memory footprint..
1368
     *  </pre>
1369
     *  @exception UnsupportedOperationException
1370
     */
1371
    @NotImplemented
1372
    public Map<CellAddress, ? extends Comment> getCellComments() {
1373
        throw new UnsupportedOperationException("Operation not supported.");   
1374
    }
1375
1376
    /**
1377
     *  <pre>
1378
     * Not supported due to memory footprint.
1379
     *  </pre>
1380
     *  @exception UnsupportedOperationException
1381
     */
1382
    @NotImplemented
1383
    public Drawing getDrawingPatriarch() {
1384
        throw new UnsupportedOperationException("Operation not supported.");  
1385
    }
1386
1387
    /**
1388
     * <pre>
1389
     * Not supported right now, as StreamedWorkbook
1390
     * supports only reading.
1391
     * </pre>
1392
     * @exception UnsupportedOperationException
1393
     */
1394
    @NotImplemented
1395
    public Drawing createDrawingPatriarch() {
1396
        throw new UnsupportedOperationException("Operation not supported.");    
1397
    }
1398
1399
    /**
1400
     * <pre>
1401
     * Will not be supported due to memory constraints
1402
     * </pre>
1403
     * @exception UnsupportedOperationException
1404
     */
1405
    @NotImplemented
1406
    public Workbook getWorkbook() {
1407
        throw new UnsupportedOperationException("Operation not supported.");    
1408
    }
1409
1410
    /**
1411
     *  <pre>
1412
     *  Returns sheet name
1413
     *  </pre>
1414
     *  @return String
1415
     */
1416
    public String getSheetName() {
1417
        return sheetName;
1418
    }
1419
    
1420
    /**
1421
     *  <pre>
1422
     * Not supported right now, as StreamedWorkbook
1423
     * supports only reading.
1424
     *  </pre>
1425
     *  
1426
     */
1427
    @NotImplemented
1428
    public void setSheetName(String sheetName) {
1429
        //to avoid setting sheet name by user
1430
        if(this.sheetName == null)this.sheetName = sheetName;
1431
    }
1432
1433
    /**
1434
     *  <pre>
1435
     * Not supported due to memory footprint.
1436
     *  </pre>
1437
     *  @exception UnsupportedOperationException
1438
     */
1439
    @NotImplemented
1440
    public boolean isSelected() {
1441
        throw new UnsupportedOperationException("Operation not supported.");    
1442
    }
1443
1444
    /**
1445
     * <pre>
1446
     * Not supported right now, as StreamedWorkbook
1447
     * supports only reading.
1448
     * </pre>
1449
     * @exception UnsupportedOperationException
1450
     */
1451
    @NotImplemented
1452
    public CellRange<? extends Cell> setArrayFormula(String formula,
1453
            CellRangeAddress range) {
1454
        throw new UnsupportedOperationException("Operation not supported.");
1455
    }
1456
1457
    /**
1458
     * <pre>
1459
     * Not supported right now, as StreamedWorkbook
1460
     * supports only reading.
1461
     * </pre>
1462
     * @exception UnsupportedOperationException
1463
     */
1464
    @NotImplemented
1465
    public CellRange<? extends Cell> removeArrayFormula(Cell cell) {
1466
        throw new UnsupportedOperationException("Operation not supported.");
1467
    }
1468
1469
    /**
1470
     *  <pre>
1471
     * Not supported due to memory footprint.
1472
     *  </pre>
1473
     *  @exception UnsupportedOperationException
1474
     */
1475
    @NotImplemented
1476
    public DataValidationHelper getDataValidationHelper() {
1477
        throw new UnsupportedOperationException("Operation not supported.");
1478
    }
1479
1480
    /**
1481
     *  <pre>
1482
     * Not supported due to memory footprint.
1483
     *  </pre>
1484
     *  @exception UnsupportedOperationException
1485
     */
1486
    @NotImplemented
1487
    public List<? extends DataValidation> getDataValidations() {
1488
        throw new UnsupportedOperationException("Operation not supported.");
1489
    }
1490
1491
    /**
1492
     * <pre>
1493
     * Not supported right now, as StreamedWorkbook
1494
     * supports only reading.
1495
     * </pre>
1496
     * @exception UnsupportedOperationException
1497
     */
1498
    @NotImplemented
1499
    public void addValidationData(DataValidation dataValidation) {
1500
        throw new UnsupportedOperationException("Operation not supported.");
1501
    }
1502
1503
    /**
1504
     * <pre>
1505
     * Not supported right now, as StreamedWorkbook
1506
     * supports only reading.
1507
     * </pre>
1508
     * @exception UnsupportedOperationException
1509
     */
1510
    @NotImplemented
1511
    public AutoFilter setAutoFilter(CellRangeAddress range) {
1512
        throw new UnsupportedOperationException("Operation not supported.");
1513
    }
1514
1515
    /**
1516
     *  <pre>
1517
     * Not supported due to memory footprint.
1518
     *  </pre>
1519
     *  @exception UnsupportedOperationException
1520
     */
1521
    @NotImplemented
1522
    public SheetConditionalFormatting getSheetConditionalFormatting() {
1523
        throw new UnsupportedOperationException("Operation not supported.");
1524
    }
1525
1526
    /**
1527
     *  <pre>
1528
     * Not supported due to memory footprint.
1529
     *  </pre>
1530
     *  @exception UnsupportedOperationException
1531
     */
1532
    @NotImplemented
1533
    public CellRangeAddress getRepeatingRows() {
1534
        throw new UnsupportedOperationException("Operation not supported.");
1535
    }
1536
1537
    /**
1538
     *  <pre>
1539
     * Not supported due to memory footprint.
1540
     *  </pre>
1541
     */
1542
    @NotImplemented
1543
    public CellRangeAddress getRepeatingColumns() {
1544
        throw new UnsupportedOperationException("Operation not supported.");
1545
    }
1546
1547
    /**
1548
     * <pre>
1549
     * Not supported right now, as StreamedWorkbook
1550
     * supports only reading.
1551
     * </pre>
1552
     * @exception UnsupportedOperationException
1553
     */
1554
    @NotImplemented
1555
    public void setRepeatingRows(CellRangeAddress rowRangeRef) {
1556
        throw new UnsupportedOperationException("Operation not supported.");
1557
    }
1558
1559
    /**
1560
     * <pre>
1561
     * Not supported right now, as StreamedWorkbook
1562
     * supports only reading.
1563
     * </pre>
1564
     * @exception UnsupportedOperationException
1565
     */
1566
    @NotImplemented
1567
    public void setRepeatingColumns(CellRangeAddress columnRangeRef) {
1568
        throw new UnsupportedOperationException("Operation not supported.");
1569
    }
1570
1571
    /**
1572
     *  <pre>
1573
     * Not supported due to memory footprint.
1574
     *  </pre>
1575
     *  @exception UnsupportedOperationException
1576
     */
1577
    @NotImplemented
1578
    public int getColumnOutlineLevel(int columnIndex) {
1579
        throw new UnsupportedOperationException("Operation not supported.");
1580
    }
1581
1582
    /**
1583
     *  <pre>
1584
     * Not supported due to memory footprint.
1585
     *  </pre>
1586
     *  @exception UnsupportedOperationException
1587
     */
1588
    @NotImplemented
1589
    public Hyperlink getHyperlink(int row, int column) {
1590
        throw new UnsupportedOperationException("Operation not supported.");
1591
    }
1592
1593
    /**
1594
     *  <pre>
1595
     * Not supported due to memory footprint.
1596
     *  </pre>
1597
     *  @exception UnsupportedOperationException
1598
     */
1599
    @NotImplemented
1600
    public Hyperlink getHyperlink(CellAddress addr) {
1601
        throw new UnsupportedOperationException("Operation not supported.");
1602
    }
1603
1604
1605
    /**
1606
     * <pre>
1607
     * Will not be supported due to memory constraints
1608
     * </pre>
1609
     * @exception UnsupportedOperationException
1610
     */
1611
    @NotImplemented
1612
    public List<? extends Hyperlink> getHyperlinkList() {
1613
        throw new UnsupportedOperationException("Operation not supported.");
1614
    }
1615
1616
    /**
1617
     *  <pre>
1618
     * Not supported due to memory footprint.
1619
     *  </pre>
1620
     *  @exception UnsupportedOperationException
1621
     */
1622
    @NotImplemented
1623
    public CellAddress getActiveCell() {
1624
        throw new UnsupportedOperationException("Operation not supported.");
1625
    }
1626
1627
    /**
1628
     * <pre>
1629
     * Not supported right now, as StreamedWorkbook
1630
     * supports only reading.
1631
     * </pre>
1632
     * @exception UnsupportedOperationException
1633
     * 
1634
     */
1635
    @NotImplemented
1636
    public void setActiveCell(CellAddress address) { 
1637
        throw new UnsupportedOperationException("Operation not supported.");
1638
    }
1639
1640
1641
1642
    
1643
    
1644
    
1645
}
(-)a/src/ooxml/java/org/apache/poi/xssf/streaming/reader/StreamedSheetEventHandler.java (+447 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.streaming.reader;
18
19
import java.util.ArrayList;
20
import java.util.Arrays;
21
import java.util.HashMap;
22
import java.util.Iterator;
23
import java.util.List;
24
import java.util.Map;
25
import java.util.Properties;
26
27
import javax.xml.namespace.QName;
28
import javax.xml.stream.events.Attribute;
29
import javax.xml.stream.events.Characters;
30
import javax.xml.stream.events.EndElement;
31
import javax.xml.stream.events.StartElement;
32
import javax.xml.stream.events.XMLEvent;
33
34
import org.apache.poi.ss.usermodel.Cell;
35
import org.apache.poi.ss.usermodel.CellType;
36
import org.apache.poi.ss.usermodel.DataFormatter;
37
import org.apache.poi.xssf.model.SharedStringsTable;
38
import org.apache.poi.xssf.model.StylesTable;
39
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
40
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
41
42
/**
43
 * Handler class that handles the event generated by StAX parser
44
 *
45
 */
46
public class StreamedSheetEventHandler {
47
    
48
    private boolean isEndOfRow = false;
49
    private boolean isRow = false;
50
    //private boolean mergeCell = false;
51
    
52
    private String formatString = null;
53
    private int formatIndex = 0;
54
    private String cellContentType;
55
    private int rowNumber = 0;
56
    private int numberOfColumns = 0;
57
    private List<String> cellPositions = null;
58
    private String currentCellPosition = null;
59
    private int previousCellIndex = -1;
60
    //private List<String> mergeList = null;  //merge cell not supported right now. Complexity involved if multiple rows are merged.
61
    
62
    private SharedStringsTable sharedStringsTable;
63
    private StylesTable stylesTable;
64
    
65
    private DataFormatter formatter = new DataFormatter();
66
    private Properties properties = new Properties();
67
    private Map<String, String> attributes = new HashMap<String, String>();
68
    private StringBuffer sb = new StringBuffer(250); 
69
    private List<String> dateFormatsAry =  new ArrayList<String>();
70
    
71
    private StreamedRow row;
72
    private StreamedCell cell;
73
    
74
    private final String dateFormat = "m/d/yy|DD/MM/YY|[$-F800]dddd\\,\\ mmmm\\ dd\\,\\ yyyy|m/d;@|m/d/yy;@|mm/dd/yy;@|"
75
            + "[$-409]d\\-mmm;@|[$-409]d\\-mmm\\-yy;@|[$-409]dd\\-mmm\\-yy;@|[$-409]mmm\\-yy;@|[$-409]mmmm\\-yy;@|"
76
            + "[$-409]mmmm\\ d\\,\\ yyyy;@|[$-409]m/d/yy\\ h:mm\\ AM/PM;@|m/d/yy\\ h:mm;@|[$-409]mmmmm;@|"
77
            + "[$-409]mmmmm\\-yy;@|m/d/yyyy;@|[$-409]d\\-mmm\\-yyyy;@|[$-F400]h:mm:ss\\ AM/PM|"
78
            + "h:mm;@|[$-409]h:mm\\ AM/PM;@|h:mm:ss;@|[$-409]h:mm:ss\\ AM/PM;@|mm:ss.0;@|[h]:mm:ss;@|"
79
            + "[$-409]m/d/yy\\ h:mm\\ AM/PM;@|DD/MM/YYYY";
80
    
81
    public static final String DEFAULT_CELL_TYPE = "DEFAULT";
82
    public static final String STRING_CELL_TYPE = "STRING";
83
    public static final String BOOLEAN_CELL_TYPE = "BOOLEAN";
84
    public static final String DATE_CELL_TYPE = "DATE";
85
    public static final String FORMULA_CELL_TYPE = "FORMULA";
86
    public static final String NUMERIC_CELL_TYPE = "NUMERIC";
87
        
88
    
89
    /**
90
     * Constructor
91
     * @param sharedStringsTable
92
     * @param stylesTable
93
     */
94
    public StreamedSheetEventHandler(SharedStringsTable sharedStringsTable, StylesTable stylesTable){
95
        this.sharedStringsTable = sharedStringsTable;
96
        this.stylesTable = stylesTable;
97
        /*try{
98
            properties.load(getClass().getClassLoader().getResourceAsStream("excelreader.properties"));
99
        }catch(Exception e){
100
            e.printStackTrace();
101
        }*/
102
        
103
        /*if(properties.get("date.formatStrings") != null){
104
            dateFormat = properties.get("date.formatStrings").toString();           
105
        }*/
106
        
107
        dateFormatsAry.addAll(Arrays.asList(dateFormat.split("\\|")));
108
        
109
    }
110
    
111
    /**
112
     * Handler method for handling the event generated for StAX parser.
113
     * For each XML event(Start Tag, End Tag & Characters), StAX parser will 
114
     * generate event. This event will be handled by this method.
115
     * Attributes of each element are put in a map with key as attribute 
116
     * and value as attribute value.
117
     * @param event
118
     */
119
    public void handleEvent(XMLEvent event){
120
        switch(event.getEventType()){
121
        case XMLEvent.START_ELEMENT:
122
            StartElement startElemet = event.asStartElement();
123
            QName startName = startElemet.getName();
124
            String name = startName.getLocalPart();                 
125
            Iterator<Attribute> iterator = startElemet.getAttributes();
126
            while(iterator.hasNext()){
127
                Attribute attribute = iterator.next();                  
128
                attributes.put(attribute.getName().getLocalPart(), attribute.getValue());
129
            }
130
            if((name.trim().equals("row")) && (attributes.size() > 0)){
131
                isRow = true;
132
            }
133
            
134
            /*else if(name.trim().equals("mergeCell")){
135
                mergeCell = true;
136
            }
137
            
138
            if(isRow || mergeCell){
139
                startElement(name);
140
            }*/
141
            
142
            if(isRow){
143
                startElement(name);
144
            }
145
            break;
146
        case XMLEvent.CHARACTERS:
147
            Characters chars = event.asCharacters();
148
            if(isRow){
149
                characters(chars.getData());
150
            }
151
            break;
152
        case XMLEvent.END_ELEMENT:
153
            EndElement endElement = event.asEndElement();
154
            QName endName = endElement.getName();
155
            String endTageName = endName.getLocalPart();
156
            endElement(endTageName);
157
            attributes.clear();
158
            break;
159
        }
160
    }
161
    
162
    /**
163
     * All the start element events are handled here.
164
     * It identifies the things like rowNumber, cell content type etc
165
     * @param name
166
     */
167
    private void startElement(String name) {
168
        if(name.equals("row")) {
169
            previousCellIndex = -1;
170
            isEndOfRow = false;
171
            rowNumber = (Integer.parseInt(attributes.get("r")) - 1);
172
            row = new StreamedRow(rowNumber);
173
            if(rowNumber == 0){
174
                cellPositions = new ArrayList<String>();
175
            }
176
        }else if(name.equals("c")){
177
            String cellPosition =  attributes.get("r").toUpperCase();
178
            cellPosition = cellPosition.replaceAll(String.valueOf(rowNumber+1), "").trim();
179
            currentCellPosition = cellPosition;
180
            if(rowNumber == 0){
181
                numberOfColumns ++;                             
182
                cellPositions.add(cellPosition);
183
            }
184
185
            cellContentType = getCellContentType();
186
        }else if(name.equals("f")){
187
            cellContentType = FORMULA_CELL_TYPE;
188
        }
189
        
190
        /*else if(name.equals("mergeCell")){
191
            if(mergeList == null){
192
                mergeList = 
193
            }
194
        }*/
195
    }
196
    
197
    
198
    /**
199
     * This method is invoked on end element event.
200
     * Mostly used for setting the default values before handling 
201
     * next start element.
202
     * All data captured in characters event are stored here.
203
     * Data will be stored only on reaching the end element.
204
     * @param name
205
     */
206
    private void endElement(String name) {
207
        if(name.equals("c")){
208
            if(isRow){
209
                storeData(sb.toString());
210
            }
211
            cellContentType = DEFAULT_CELL_TYPE;
212
            formatString = null;
213
            formatIndex = 0;            
214
            currentCellPosition = null;
215
            previousCellIndex++;
216
            sb.delete(0, sb.length());
217
        }else if(name.equals("row")){
218
            isEndOfRow = true;
219
            isRow = false;
220
        }else if(name.equals("f")){
221
            cellContentType = DEFAULT_CELL_TYPE;
222
        }
223
        
224
        /*else if(name.equals("mergeCell")){
225
            mergeCell = false;
226
        }*/
227
    }
228
    
229
    /**
230
     * Captures the data 
231
     * @param data
232
     */
233
    private void characters(String data) {
234
        if(!(cellContentType.equals(FORMULA_CELL_TYPE))){           
235
            sb.append(data);
236
        }
237
    }
238
    
239
    /**
240
     * Creates cells and store data
241
     * @param data
242
     */
243
    private void storeData(String data){            
244
        if (!(cellContentType.equals(FORMULA_CELL_TYPE))) {
245
            if(cellContentType.equals(STRING_CELL_TYPE)){
246
                data = getStringData(data);
247
            }else if(cellContentType.equals(DATE_CELL_TYPE)){
248
                data = getDateAsString(data);
249
            }else if(cellContentType.equals(BOOLEAN_CELL_TYPE)){
250
                if(data.trim().equals("1")){
251
                    data = "TRUE";
252
                }else if(data.trim().equals("0")){
253
                    data = "FALSE";
254
                }else if(data.trim().equals("")){
255
                    data = null;
256
                }else{
257
                    try{
258
                        int value = Integer.parseInt(data);
259
                        if(value > 0){
260
                            data = "TRUE";
261
                        }
262
                    }catch(Exception e){
263
                        data = null;
264
                    }
265
                }
266
            }
267
            
268
            if(cellPositions != null){
269
                fillEmptyCells();
270
            }
271
            
272
            cell = new StreamedCell();
273
            cell.setValue(data);
274
            cell.setCellNumber(previousCellIndex+1);
275
            setCellType(cell, cellContentType, data);
276
            row.getCells().add(cell);
277
                    
278
        }
279
    }
280
    
281
    /**
282
     * Set the content type of cell.
283
     * 
284
     *
285
     * @param cell
286
     * @param contentType
287
     * @param data
288
     */
289
    private void setCellType(Cell cell, String contentType, String data){
290
        
291
        if(contentType.equals(BOOLEAN_CELL_TYPE)){
292
            cell.setCellType(CellType.BOOLEAN);
293
        }
294
        else if(contentType.equals(STRING_CELL_TYPE)){
295
            if(data != null && data.trim().isEmpty()){
296
                cell.setCellType(CellType.BLANK);
297
            }else{
298
                cell.setCellType(CellType.STRING);
299
            }
300
        }else if(contentType.equals(FORMULA_CELL_TYPE)) {
301
            cell.setCellType(CellType.FORMULA);
302
        }
303
        
304
    }
305
    
306
    
307
    /**
308
     * Identifies the cell content type
309
     * @return
310
     */
311
    private String getCellContentType(){
312
        String cellConentType = DEFAULT_CELL_TYPE;
313
        String cellType = attributes.get("t");
314
        if((null != cellType) && (cellType.equals("s"))){
315
            cellConentType = STRING_CELL_TYPE;
316
        }else if((null != cellType) && (equals("b"))){
317
            cellConentType = BOOLEAN_CELL_TYPE;
318
        }else{
319
            
320
            if(checkForDate()){
321
                cellConentType = DATE_CELL_TYPE;
322
            }else if(checkForBoolean()){
323
                cellConentType = BOOLEAN_CELL_TYPE;
324
            }
325
        }
326
        return cellConentType;
327
    }
328
    
329
    
330
    
331
    /**
332
     * Identifies if the given cell is a boolean or not
333
     * @return
334
     */
335
    private boolean checkForBoolean(){
336
        String cellStyleType = attributes.get("s");
337
        if(cellStyleType != null){
338
            int styleIndex = Integer.parseInt(cellStyleType);
339
            XSSFCellStyle style = stylesTable.getStyleAt(styleIndex);
340
            formatIndex = style.getDataFormat();
341
            formatString = style.getDataFormatString();
342
            if(formatString.contains("TRUE")){
343
                return true;
344
            }else{
345
                return false;
346
            }
347
        }else{
348
            return false;
349
        }
350
    }
351
352
    /**
353
     * identifies if the given cell is a Date cell or not
354
     * @return
355
     */
356
    private boolean checkForDate(){
357
        boolean isDate = false;
358
        String cellStyleType = attributes.get("s");
359
        if(cellStyleType != null){
360
            int styleIndex = Integer.parseInt(cellStyleType);
361
            XSSFCellStyle style = stylesTable.getStyleAt(styleIndex);
362
            formatIndex = style.getDataFormat();
363
            formatString = style.getDataFormatString();
364
            if(dateFormatsAry.contains(formatString.trim())){               
365
                isDate = true;
366
            }
367
        }
368
        
369
        return isDate;
370
    }
371
    
372
373
    /**
374
     * fetches the String data from SharedStringsTable.xml
375
     * @param data
376
     * @return
377
     */
378
    private String getStringData(String data){
379
        int index = Integer.parseInt(data);
380
        return new XSSFRichTextString(sharedStringsTable.getEntryAt(index)).toString().trim();
381
    }
382
    
383
    /**
384
     * check the styles applied to the cell and fetches the exact content of date cell
385
     * @param data
386
     * @return
387
     */
388
    private String getDateAsString(String data) {
389
        if ((data != null) && (!(data.trim().equals("")))) {
390
            /*return formatter.formatRawCellContents(Double.parseDouble(data),
391
                    formatIndex, formatString);*/
392
            
393
            /*
394
             * All dates are formatted with 'DD/MM/YYYY', this is to avoid confusion between
395
             * 10/12/2017 & 10/12/1917. Otherwise both will be read as 10/12/17 if the format 
396
             * is DD/MM/YY
397
             */
398
            return formatter.formatRawCellContents(Double.parseDouble(data),
399
                    formatIndex, "DD/MM/YYYY");
400
        } else {
401
            return null;
402
        }
403
    }
404
405
    
406
    /**
407
     * Used to fill empty cells as null
408
     */
409
    private void fillEmptyCells() {
410
        int currentCellIndex = cellPositions.indexOf(currentCellPosition);
411
        if ((currentCellIndex - previousCellIndex) > 1) {
412
            for (int i = (previousCellIndex + 1); i < currentCellIndex; i++) {
413
                cell = new StreamedCell();
414
                cell.setValue(null);
415
                row.getCells().add(cell);
416
            }
417
            
418
            previousCellIndex = currentCellIndex;
419
        }
420
    }
421
422
    public boolean isEndOfRow() {
423
        return isEndOfRow;
424
    }
425
426
    public void setEndOfRow(boolean isEndOfRow) {
427
        this.isEndOfRow = isEndOfRow;
428
    }
429
430
    public int getRowNumber() {
431
        return rowNumber;
432
    }
433
434
    public int getNumberOfColumns() {
435
        return numberOfColumns;
436
    }
437
438
    public List<String> getCellPositions() {
439
        return cellPositions;
440
    }
441
442
    public StreamedRow getRow() {
443
        return row;
444
    }
445
    
446
    
447
}
(-)a/src/ooxml/java/org/apache/poi/xssf/streaming/reader/StreamedWorkbook.java (+1070 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.streaming.reader;
18
19
import java.io.File;
20
import java.io.IOException;
21
import java.io.InputStream;
22
import java.io.OutputStream;
23
import java.util.ArrayList;
24
import java.util.Iterator;
25
import java.util.List;
26
27
import javax.xml.parsers.DocumentBuilder;
28
import javax.xml.parsers.DocumentBuilderFactory;
29
import javax.xml.stream.XMLEventReader;
30
import javax.xml.stream.XMLInputFactory;
31
import javax.xml.stream.XMLStreamException;
32
import javax.xml.xpath.XPath;
33
import javax.xml.xpath.XPathConstants;
34
import javax.xml.xpath.XPathExpression;
35
import javax.xml.xpath.XPathFactory;
36
37
import org.apache.poi.openxml4j.opc.OPCPackage;
38
import org.apache.poi.ss.SpreadsheetVersion;
39
import org.apache.poi.ss.formula.udf.UDFFinder;
40
import org.apache.poi.ss.usermodel.CellStyle;
41
import org.apache.poi.ss.usermodel.CreationHelper;
42
import org.apache.poi.ss.usermodel.DataFormat;
43
import org.apache.poi.ss.usermodel.Font;
44
import org.apache.poi.ss.usermodel.Name;
45
import org.apache.poi.ss.usermodel.PictureData;
46
import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
47
import org.apache.poi.ss.usermodel.Sheet;
48
import org.apache.poi.ss.usermodel.SheetVisibility;
49
import org.apache.poi.ss.usermodel.Workbook;
50
import org.apache.poi.util.NotImplemented;
51
import org.apache.poi.util.POILogFactory;
52
import org.apache.poi.util.POILogger;
53
import org.apache.poi.xssf.eventusermodel.XSSFReader;
54
import org.apache.poi.xssf.model.SharedStringsTable;
55
import org.apache.poi.xssf.model.StylesTable;
56
import org.w3c.dom.Document;
57
import org.w3c.dom.NodeList;
58
59
/**
60
 * Represents the excel workbook. 
61
 * This version of Workbook is used fore reading very large excel files
62
 * with a less memory footprint. It does not support creation of a workbook.
63
 * It uses StAX(Streaming API for XML) to stream the spreadsheet.
64
 * In order to reduce the memory footprint, only minimal functionalities are
65
 * supported.
66
 *
67
 */
68
public class StreamedWorkbook implements Workbook{
69
    
70
    private static final POILogger logger = POILogFactory.getLogger(StreamedWorkbook.class);
71
    
72
    private File inputFile;
73
    
74
    private Iterator<InputStream> sheetIterator;
75
    private SharedStringsTable sharedStringsTable;
76
    private StylesTable stylesTable;
77
    private XSSFReader globalReader;
78
    private List<StreamedSheet> sheetList = null;
79
    private boolean isClosed;
80
    
81
    private static final String ACTIVE_SHEET_PATH = "//workbookView/@activeTab";
82
    private static final String SHEET_NAME_PATH = "//sheets/sheet/@name";
83
    private static final String VISIBLE_SHEET_PATH = "//sheets/sheet[@state='visible']/@sheetId";
84
    private static final String HIDDEN_SHEET_PATH = "//sheets/sheet[@state='hidden']/@sheetId";
85
    private static final String VERY_HIDDEN_SHEET_PATH = "//sheets/sheet[@state='veryHidden']/@sheetId";
86
    
87
    /**
88
     * <pre>
89
     * Accepts the file path and return an instance of StreamedWorkBook
90
     *</pre>
91
     * @param filePath
92
     * @throws Exception 
93
     */
94
    public StreamedWorkbook(String filePath) throws Exception{
95
        if((filePath != null) && !(filePath.trim().isEmpty())){
96
            inputFile = new File(filePath);
97
            
98
            if(inputFile != null){
99
                XSSFReader reader = getExcelReader(inputFile);
100
                if(reader != null){
101
                    this.sheetIterator = reader.getSheetsData();
102
                    this.sharedStringsTable = reader.getSharedStringsTable();
103
                    this.stylesTable = reader.getStylesTable();
104
                    this.globalReader = reader;
105
                }
106
            }
107
            
108
        }else{
109
            throw new Exception("No sheets found");
110
        }
111
    }
112
    
113
    /**
114
     * <pre>
115
     * Fetch all sheets from given excel file
116
     * </pre>
117
     * @return Iterator<StreamedSheet> 
118
     * @throws Exception
119
     */
120
    public Iterator<StreamedSheet> getSheetIterator() throws Exception{
121
        
122
        return getAllSheets();
123
    }
124
    
125
    
126
     /**
127
     * Returns the list of sheets for the given excel file
128
     * @param file
129
     * @return Iterator<StreamedSheet>
130
     */
131
    private Iterator<StreamedSheet>  getAllSheets(){
132
        
133
        return getStreamedSheetIterator();
134
    }
135
    
136
    private Iterator<StreamedSheet> getStreamedSheetIterator(){
137
        XMLInputFactory factory = null; 
138
        
139
        if(sheetIterator != null){
140
            factory = XMLInputFactory.newInstance();
141
            sheetList =  new ArrayList<StreamedSheet>();
142
            int sheetNumber = 0;
143
            Object[] sheetNames = getValuesFromWorkbookData(SHEET_NAME_PATH);
144
            while(sheetIterator.hasNext()){
145
                InputStream sheetInputStream = sheetIterator.next();
146
                StreamedSheet sheet = null;
147
                try {
148
                    sheet = createStreamedSheet(factory.createXMLEventReader(sheetInputStream), sheetNumber, sheetNames[sheetNumber].toString());
149
                    sheetList.add(sheet);
150
                    sheetNumber++;
151
                } catch (XMLStreamException e) {
152
                    logger.log(POILogger.ERROR, "Exception while reading the workbook. "+e.getMessage());
153
                }
154
            }
155
        }else{
156
            throw new RuntimeException("Workbook already closed");
157
        }
158
        
159
        return sheetList.iterator();
160
        
161
    }
162
    
163
164
    /**
165
     * Creates and returns the instance of StreamedSheet
166
     *
167
     * @param parser
168
     * @param sheetNumber
169
     * @param sheetName
170
     * @return StreamedSheet
171
     */
172
    private StreamedSheet createStreamedSheet(XMLEventReader parser,int sheetNumber, String sheetName){
173
        StreamedSheet sheet = new StreamedSheet();
174
        sheet.setXmlParser(parser);
175
        sheet.setSharedStringsTable(sharedStringsTable);
176
        sheet.setStylesTable(stylesTable);
177
        sheet.setSheetNumber(sheetNumber);
178
        sheet.setSheetName(sheetName);
179
        sheet.createEventHandler();
180
        
181
        return sheet;
182
    }
183
    
184
    
185
    
186
    /**
187
     * Receives the excel file and returns the file excel file reader
188
     * @param inputStream
189
     * @return
190
     * @throws Exception
191
     */
192
    private XSSFReader getExcelReader(File file) throws Exception{
193
        XSSFReader reader = null;
194
        OPCPackage pkg = null;
195
        pkg = OPCPackage.open(file);
196
        reader = new XSSFReader(pkg);
197
        return reader;
198
    }
199
    
200
    
201
    
202
    /**
203
     * <pre>
204
     * Convenience method to get the active sheet.  The active sheet is is the sheet
205
     * which is currently displayed when the workbook is viewed in Excel.
206
     * 'Selected' sheet(s) is a distinct concept.
207
     * </pre>
208
     * 
209
     * @return int
210
     */
211
    public int getActiveSheetIndex() {
212
            
213
        return Integer.parseInt(getValuesFromWorkbookData(ACTIVE_SHEET_PATH)[0].toString());
214
        
215
    }
216
217
218
    /**
219
     * <pre>
220
     * Not supported right now, as StreamedWorkbook
221
     * supports only reading.
222
     * </pre>
223
     * 
224
     * @exception UnsupportedOperationException
225
     */
226
    @NotImplemented
227
    public void setActiveSheet(int sheetIndex) {
228
        throw new UnsupportedOperationException("Not supported due to memory footprint");
229
    }
230
231
    /**
232
     * <pre>
233
     * Returns the sheet number of the first visible sheet.
234
     * </pre>
235
     * @return int
236
     */
237
    public int getFirstVisibleTab() {
238
        Object[] visibleTabs = getValuesFromWorkbookData(VISIBLE_SHEET_PATH);
239
        
240
        return (Integer.parseInt(visibleTabs[0].toString())-1);
241
    }
242
243
    /**
244
     * <pre>
245
     * Not supported right now, as StreamedWorkbook
246
     * supports only reading.
247
     * </pre>
248
     * @exception UnsupportedOperationException
249
     * 
250
     */
251
    @NotImplemented
252
    public void setFirstVisibleTab(int sheetIndex) {
253
        throw new UnsupportedOperationException("Not implemented yet");
254
    }
255
256
    /**
257
     * <pre>
258
     * Will be supported in the future.
259
     * </pre>
260
     * @exception UnsupportedOperationException
261
     * 
262
     */
263
    @NotImplemented
264
    public void setSheetOrder(String sheetname, int pos) {
265
        throw new UnsupportedOperationException("Not implemented yet");
266
    }
267
268
    /**
269
     * <pre>
270
     * Will be supported in the future.
271
     * </pre>
272
     * @exception UnsupportedOperationException
273
     * 
274
     */
275
    @NotImplemented
276
    public void setSelectedTab(int index) {
277
        throw new UnsupportedOperationException("Not implemented yet");
278
    }
279
280
    /**
281
     * <pre>
282
     * Not supported right now, as StreamedWorkbook
283
     * supports only reading.
284
     * </pre>
285
     * @exception UnsupportedOperationException
286
     * 
287
     */
288
    @NotImplemented
289
    public void setSheetName(int sheet, String name) {
290
        throw new UnsupportedOperationException("Not supported due to memory footprint");
291
    }
292
293
    /**
294
     * <pre>
295
     * Returns the sheet name of specified index
296
     * </pre>
297
     * @return String;
298
     * 
299
     */    
300
    public String getSheetName(int sheet) {
301
        return getValuesFromWorkbookData(SHEET_NAME_PATH)[sheet].toString();
302
    }
303
304
    /**
305
     * <pre>
306
     * Returns the sheet index for the sheet name given
307
     * </pre>
308
     * @return int
309
     * 
310
     */
311
    public int getSheetIndex(String name) {
312
        int index = 0;
313
        for(Object sheetName: getValuesFromWorkbookData(SHEET_NAME_PATH)){
314
            if(sheetName.toString().equals(name)){
315
                return index;
316
            }
317
            index++;
318
        }
319
        
320
        return -1;
321
    }
322
323
    /**
324
     * <pre>
325
     * Will be supported in the future.
326
     * </pre>
327
     * @exception UnsupportedOperationException
328
     * 
329
     */
330
    @NotImplemented
331
    public int getSheetIndex(Sheet sheet) {
332
        throw new UnsupportedOperationException("Not implemented yet");
333
    }
334
335
    /**
336
     * <pre>
337
     * Not supported right now, as StreamedWorkbook
338
     * supports only reading.
339
     * </pre>
340
     * @exception UnsupportedOperationException
341
     * 
342
     */ 
343
    @NotImplemented
344
    public Sheet createSheet() {
345
        throw new UnsupportedOperationException("Not supported due to memory footprint");
346
    }
347
348
    /**
349
     * <pre>
350
     * Not supported right now, as StreamedWorkbook
351
     * supports only reading.
352
     * </pre>
353
     * @exception UnsupportedOperationException
354
     * 
355
     * 
356
     */
357
    @NotImplemented
358
    public Sheet createSheet(String sheetname) {
359
        throw new UnsupportedOperationException("Not supported due to memory footprint");
360
    }
361
362
    /**
363
     * <pre>
364
     * Not supported right now, as StreamedWorkbook
365
     * supports only reading.
366
     * </pre>
367
     * @exception UnsupportedOperationException
368
     * 
369
     */
370
    @NotImplemented
371
    public Sheet cloneSheet(int sheetNum) {
372
        throw new UnsupportedOperationException("Not supported due to memory footprint");
373
    }
374
375
    /**
376
     * <pre>
377
     * Use Iterator<StreamedSheet> getSheetIterator() instead.
378
     * </pre>
379
     * @exception UnsupportedOperationException
380
     */
381
    @NotImplemented
382
    public Iterator<Sheet> sheetIterator() {
383
        throw new UnsupportedOperationException("Not implemented yet. Use getSheetIterator()");
384
    }
385
386
    /**
387
     * <pre>
388
     *  Returns the number of sheets,
389
     * </pre>
390
     * @return int representing the number of sheets in workbook
391
     */
392
    public int getNumberOfSheets() {
393
        int sheetCount = 0;
394
        
395
        if(this.sheetIterator != null){
396
            while(sheetIterator.hasNext()){
397
                sheetIterator.next();
398
                sheetCount++;
399
            }
400
        }else{
401
            logger.log(POILogger.ERROR, "Workbook already closed");
402
        }
403
        
404
        
405
        return sheetCount;
406
    }
407
408
    /**
409
     * <pre>
410
     *  Returns sheet at specified index
411
     * </pre>
412
     * @return Sheet for the specified index
413
     */
414
    public Sheet getSheetAt(int index) {
415
        if(sheetList == null && !isClosed){
416
            getAllSheets();
417
        }
418
        
419
        if(sheetList != null){
420
            for(StreamedSheet sheet: sheetList){
421
                if(sheet.getSheetNumber() == index)return sheet;
422
            }
423
        }
424
        
425
        return null;
426
    }
427
428
    /**
429
     * <pre>
430
     * Returns the sheet with specified name
431
     * </pre>
432
     * 
433
     */
434
    public Sheet getSheet(String name) {
435
        
436
        if(sheetList == null && !isClosed){
437
            getAllSheets();
438
        }
439
        
440
        if(sheetList != null){
441
            for(StreamedSheet sheet: sheetList){
442
                if(sheet.getSheetName().equals(name))return sheet;
443
            }
444
        }
445
        
446
        return null;
447
    }
448
449
    /**
450
     * <pre>
451
     * Not supported right now, as StreamedWorkbook
452
     * supports only reading.
453
     * </pre>
454
     * @exception UnsupportedOperationException
455
     */
456
    @NotImplemented
457
    public void removeSheetAt(int index) {
458
        throw new UnsupportedOperationException("Not supported due to memory footprint");
459
    }
460
461
    /**
462
     * <pre>
463
     * Not supported right now, as StreamedWorkbook
464
     * supports only reading.
465
     * </pre>
466
     * @exception UnsupportedOperationException
467
     */
468
    @NotImplemented
469
    public Font createFont() {
470
        throw new UnsupportedOperationException("Not supported due to memory footprint");
471
    }
472
473
474
    /**
475
     * <pre>
476
     * Will be supported in the future.
477
     * </pre>
478
     * @exception UnsupportedOperationException
479
     */
480
    @NotImplemented
481
    public Font findFont(short boldWeight, short color, short fontHeight,
482
            String name, boolean italic, boolean strikeout, short typeOffset,
483
            byte underline) {
484
        throw new UnsupportedOperationException("Not implemented yet");
485
    }
486
487
    /**
488
     * <pre>
489
     * Will be supported in the future.
490
     * </pre>
491
     * @exception UnsupportedOperationException
492
     */
493
    @NotImplemented
494
    public Font findFont(boolean bold, short color, short fontHeight,
495
            String name, boolean italic, boolean strikeout, short typeOffset,
496
            byte underline) {
497
        throw new UnsupportedOperationException("Not implemented yet");
498
    }
499
500
    /**
501
     * <pre>
502
     * Will be supported in the future.
503
     * </pre>
504
     * @exception UnsupportedOperationException
505
     */
506
    @NotImplemented
507
    public short getNumberOfFonts() {
508
        throw new UnsupportedOperationException("Not implemented yet");
509
    }
510
511
    /**
512
     * <pre>
513
     * Will be supported in the future.
514
     * </pre>
515
     * @exception UnsupportedOperationException
516
     */
517
    @NotImplemented
518
    public Font getFontAt(short idx) {
519
        throw new UnsupportedOperationException("Not implemented yet");
520
    }
521
522
    /**
523
     * <pre>
524
     * Not supported right now, as StreamedWorkbook
525
     * supports only reading.
526
     * </pre>
527
     * @exception UnsupportedOperationException
528
     */
529
    public CellStyle createCellStyle() {
530
        throw new UnsupportedOperationException("Not supported due to memory footprint");
531
    }
532
533
534
    /**
535
     * <pre>
536
     * Will be supported in the future.
537
     * </pre>
538
     * @exception UnsupportedOperationException
539
     */
540
    @NotImplemented
541
    public int getNumCellStyles() {
542
        throw new UnsupportedOperationException("Not implemented yet");
543
    }
544
545
    /**
546
     * <pre>
547
     * Not Suppored due to memory footprint.
548
     * </pre>
549
     * @exception UnsupportedOperationException
550
     */
551
    @NotImplemented
552
    public CellStyle getCellStyleAt(int idx) {
553
        throw new UnsupportedOperationException("Not supported due to memory footprint");
554
    }
555
556
    
557
    /**
558
     * <pre>
559
     * Not supported right now, as StreamedWorkbook
560
     * supports only reading.
561
     * </pre>
562
     * @exception UnsupportedOperationException
563
     */  
564
    @NotImplemented
565
    public void write(OutputStream stream) throws IOException {
566
        throw new UnsupportedOperationException("Not supported due to memory footprint");
567
    }
568
569
    /**
570
     * <pre>
571
     * Close the workbook
572
     * </pre>
573
     * 
574
     */    
575
    public void close() throws IOException {
576
        if(sheetIterator != null){
577
            while(sheetIterator.hasNext()){
578
                sheetIterator.next().close();
579
            }
580
            sheetIterator = null;
581
        }
582
        
583
        if(sheetList != null){
584
            sheetList.clear();
585
            sheetList = null;
586
        }
587
        
588
        isClosed = true;
589
    }
590
591
    /**
592
     * <pre>
593
     * Will be supported in the future.
594
     * </pre>
595
     * @exception UnsupportedOperationException
596
     */  
597
    @NotImplemented
598
    public int getNumberOfNames() {
599
        throw new UnsupportedOperationException("Not implemented yet");
600
    }
601
602
    /**
603
     * <pre>
604
     * Will be supported in the future.
605
     * </pre>
606
     * @exception UnsupportedOperationException
607
     */
608
    @NotImplemented
609
    public Name getName(String name) {
610
        throw new UnsupportedOperationException("Not implemented yet");
611
    }
612
613
    /**
614
     * <pre>
615
     * Will be supported in the future.
616
     * </pre>
617
     * @exception UnsupportedOperationException
618
     */
619
    @NotImplemented
620
    public List<? extends Name> getNames(String name) {
621
        throw new UnsupportedOperationException("Not implemented yet");
622
    }
623
624
    /**
625
     * <pre>
626
     * Will be supported in the future.
627
     * </pre>
628
     * @exception UnsupportedOperationException
629
     */
630
    @NotImplemented
631
    public List<? extends Name> getAllNames() {
632
        throw new UnsupportedOperationException("Not implemented yet");
633
    }
634
635
    /**
636
     * <pre>
637
     * Will be supported in the future.
638
     * </pre>
639
     * @exception UnsupportedOperationException
640
     */
641
    @NotImplemented
642
    public Name getNameAt(int nameIndex) {
643
        throw new UnsupportedOperationException("Not implemented yet");
644
    }
645
646
    
647
    /**
648
     * <pre>
649
     * Not supported right now, as StreamedWorkbook
650
     * supports only reading.
651
     * </pre>
652
     * @exception UnsupportedOperationException
653
     */ 
654
    @NotImplemented
655
    public Name createName() {
656
        throw new UnsupportedOperationException("Not supported due to memory footprint");
657
    }
658
659
    /**
660
     * <pre>
661
     * Will be supported in the future.
662
     * </pre>
663
     * @exception UnsupportedOperationException
664
     */   
665
    @NotImplemented
666
    public int getNameIndex(String name) {
667
        throw new UnsupportedOperationException("Not implemented yet");
668
    }
669
670
    /**
671
     * <pre>
672
     * Not supported right now, as StreamedWorkbook
673
     * supports only reading.
674
     * </pre>
675
     * @exception UnsupportedOperationException
676
     */   
677
    @NotImplemented
678
    public void removeName(int index) {
679
        throw new UnsupportedOperationException("Not supported due to memory footprint");
680
    }
681
682
    /**
683
     * <pre>
684
     * Not supported right now, as StreamedWorkbook
685
     * supports only reading.
686
     * </pre>
687
     * @exception UnsupportedOperationException
688
     */  
689
    @NotImplemented
690
    public void removeName(String name) {
691
        throw new UnsupportedOperationException("Not supported due to memory footprint");
692
    }
693
694
    /**
695
     * <pre>
696
     * Not supported right now, as StreamedWorkbook
697
     * supports only reading.
698
     * </pre>
699
     * @exception UnsupportedOperationException
700
     */ 
701
    @NotImplemented
702
    public void removeName(Name name) {
703
        throw new UnsupportedOperationException("Not supported due to memory footprint");
704
    }
705
706
    /**
707
     * <pre>
708
     * Not supported right now, as StreamedWorkbook
709
     * supports only reading.
710
     * </pre>
711
     * @exception UnsupportedOperationException
712
     */     
713
    @NotImplemented
714
    public int linkExternalWorkbook(String name, Workbook workbook) {
715
        throw new UnsupportedOperationException("Not supported due to memory footprint");
716
    }
717
718
    /**
719
     * <pre>
720
     * Not supported right now, as StreamedWorkbook
721
     * supports only reading.
722
     * </pre>
723
     * 
724
     */   
725
    @NotImplemented
726
    public void setPrintArea(int sheetIndex, String reference) {
727
        throw new UnsupportedOperationException("Not supported due to memory footprint");
728
    }
729
730
    /**
731
     * <pre>
732
     * Not supported right now, as StreamedWorkbook
733
     * supports only reading.
734
     * </pre>
735
     * @exception UnsupportedOperationException
736
     */ 
737
    @NotImplemented
738
    public void setPrintArea(int sheetIndex, int startColumn, int endColumn,
739
            int startRow, int endRow) {
740
        throw new UnsupportedOperationException("Not supported due to memory footprint");
741
    }
742
743
    /**
744
     * <pre>
745
     * Will be supported in the future.
746
     * </pre>
747
     * @exception UnsupportedOperationException
748
     */ 
749
    @NotImplemented
750
    public String getPrintArea(int sheetIndex) {
751
        throw new UnsupportedOperationException("Not implemented yet");
752
    }
753
754
    /**
755
     * <pre>
756
     * Not supported right now, as StreamedWorkbook
757
     * supports only reading.
758
     * </pre>
759
     * @exception UnsupportedOperationException
760
     */    
761
    @NotImplemented
762
    public void removePrintArea(int sheetIndex) {
763
        throw new UnsupportedOperationException("Not supported due to memory footprint");
764
    }
765
766
    /**
767
     * <pre>
768
     * Will be supported in the future.
769
     * </pre>
770
     * @exception UnsupportedOperationException
771
     */ 
772
    @NotImplemented
773
    public MissingCellPolicy getMissingCellPolicy() {
774
        throw new UnsupportedOperationException("Not implemented yet");
775
    }
776
777
    /**
778
     * <pre>
779
     * Not supported right now, as StreamedWorkbook
780
     * supports only reading.
781
     * </pre>
782
     * @exception UnsupportedOperationException
783
     */  
784
    @NotImplemented
785
    public void setMissingCellPolicy(MissingCellPolicy missingCellPolicy) {
786
        throw new UnsupportedOperationException("Not supported due to memory footprint");
787
    }
788
789
    /**
790
     * <pre>
791
     * Not supported right now, as StreamedWorkbook
792
     * supports only reading.
793
     * </pre>
794
     * @exception UnsupportedOperationException
795
     */  
796
    @NotImplemented
797
    public DataFormat createDataFormat() {
798
        throw new UnsupportedOperationException("Not supported due to memory footprint");
799
    }
800
801
    /**
802
     * <pre>
803
     * Not supported right now, as StreamedWorkbook
804
     * supports only reading.
805
     * </pre>
806
     * @exception UnsupportedOperationException
807
     */
808
    @NotImplemented
809
    public int addPicture(byte[] pictureData, int format) {
810
        throw new UnsupportedOperationException("Not supported due to memory footprint");
811
    }
812
813
    /**
814
     * <pre>
815
     * Not supported due to memory footprint.
816
     * </pre>
817
     * @exception UnsupportedOperationException
818
     */ 
819
    public List<? extends PictureData> getAllPictures() {
820
        throw new UnsupportedOperationException("Not supported due to memory footprint");
821
    }
822
823
    /**
824
     * <pre>
825
     * Will be supported in the future.
826
     * </pre>
827
     * @exception UnsupportedOperationException
828
     */ 
829
    @NotImplemented
830
    public CreationHelper getCreationHelper() {
831
        throw new UnsupportedOperationException("Not implemented yet");
832
    }
833
834
    /**
835
     * <pre>
836
     * Will be supported in the future.
837
     * </pre>
838
     * @exception UnsupportedOperationException
839
     */ 
840
    @NotImplemented
841
    public boolean isHidden() {
842
        throw new UnsupportedOperationException("Not implemented yet");
843
    }
844
845
    /**
846
     * <pre>
847
     * Not supported right now, as StreamedWorkbook
848
     * supports only reading.
849
     * </pre>
850
     * @exception UnsupportedOperationException
851
     */  
852
    @NotImplemented
853
    public void setHidden(boolean hiddenFlag) {
854
        throw new UnsupportedOperationException("Not supported due to memory footprint");
855
    }
856
857
    /**
858
     * <pre>
859
     * Return true if the sheet with given index is hidden
860
     * </pre>
861
     * @return boolean
862
     */ 
863
    public boolean isSheetHidden(int sheetIx) {
864
        //throw new UnsupportedOperationException("Not implemented yet");
865
        
866
        Object[] hiddenSheetIdxAry = getValuesFromWorkbookData(HIDDEN_SHEET_PATH);
867
        
868
        for(Object o: hiddenSheetIdxAry){
869
            int index = (Integer.parseInt(o.toString())-1);
870
            if(index == sheetIx)return true;
871
        }
872
        
873
        return false;
874
    }
875
876
    /**
877
     * <pre>
878
     * Return true if the sheet with given index is veryHidden
879
     * </pre>
880
     * @return boolean
881
     */ 
882
    public boolean isSheetVeryHidden(int sheetIx) {
883
        Object[] veryHiddedSheetIdxAry = getValuesFromWorkbookData(VERY_HIDDEN_SHEET_PATH);
884
        
885
        for(Object o: veryHiddedSheetIdxAry){
886
            int index = (Integer.parseInt(o.toString())-1);
887
            if(index == sheetIx)return true;
888
        }
889
        
890
        
891
        return false;
892
    }
893
894
    /**
895
     * <pre>
896
     * Not supported right now, as StreamedWorkbook
897
     * supports only reading.
898
     * </pre>
899
     * @exception UnsupportedOperationException
900
     */ 
901
    @NotImplemented
902
    public void setSheetHidden(int sheetIx, boolean hidden) {
903
        throw new UnsupportedOperationException("Not supported due to memory footprint");
904
    }
905
906
    /**
907
     * <pre>
908
     * Not supported right now, as StreamedWorkbook
909
     * supports only reading.
910
     * </pre>
911
     * @exception UnsupportedOperationException
912
     */ 
913
    @NotImplemented
914
    public void setSheetHidden(int sheetIx, int hidden) {
915
        throw new UnsupportedOperationException("Not supported due to memory footprint");
916
    }
917
918
    /**
919
     * <pre>
920
     * Not supported right now, as StreamedWorkbook
921
     * supports only reading.
922
     * </pre>
923
     * @exception UnsupportedOperationException
924
     */ 
925
    @NotImplemented
926
    public void addToolPack(UDFFinder toopack) {
927
        throw new UnsupportedOperationException("Not supported due to memory footprint");
928
    }
929
930
    /**
931
     * <pre>
932
     * Not supported right now, as StreamedWorkbook
933
     * supports only reading.
934
     * </pre>
935
     * @exception UnsupportedOperationException
936
     */ 
937
    @NotImplemented
938
    public void setForceFormulaRecalculation(boolean value) {
939
        throw new UnsupportedOperationException("Not supported due to memory footprint");
940
    }
941
942
    /**
943
     * <pre>
944
     * Will be supported in the future.
945
     * </pre>
946
     * 
947
     */ 
948
    @NotImplemented   
949
    public boolean getForceFormulaRecalculation() {
950
        throw new UnsupportedOperationException("Not implemented yet");
951
    }
952
953
    /**
954
     * <pre>
955
     * Will be supported in the future.
956
     * </pre>
957
     * @exception UnsupportedOperationException
958
     */ 
959
    @NotImplemented
960
    public SpreadsheetVersion getSpreadsheetVersion() {
961
        throw new UnsupportedOperationException("Not implemented yet");
962
    }
963
964
965
    /**
966
     * <pre>
967
     * Use Iterator<StreamedSheet> getSheetIterator() instead.
968
     * </pre>
969
     * @exception UnsupportedOperationException
970
     */ 
971
    @NotImplemented
972
    public Iterator<Sheet> iterator() {
973
        throw new UnsupportedOperationException("Not implemented yet. Use getSheetIterator()");
974
    }
975
976
    /**
977
     * <pre>
978
     * Returns the visibility of sheet for the given index. 
979
     * </pre>
980
     * @return SheetVisibility[Hidden/Visible/VeryHidden]
981
     */ 
982
    public SheetVisibility getSheetVisibility(int sheetIx) {
983
        Object[] hiddenSheetIdxAry = getValuesFromWorkbookData(HIDDEN_SHEET_PATH);
984
        
985
        for(Object o: hiddenSheetIdxAry){
986
            int index = (Integer.parseInt(o.toString())-1);
987
            if(index == sheetIx)return SheetVisibility.HIDDEN;
988
        }
989
        
990
        Object[] visibleSheetIdxAry = getValuesFromWorkbookData(VISIBLE_SHEET_PATH);
991
        
992
        for(Object o: visibleSheetIdxAry){
993
            int index = (Integer.parseInt(o.toString())-1);
994
            if(index == sheetIx)return SheetVisibility.VISIBLE;
995
        }
996
        
997
        Object[] veryHiddedSheetIdxAry = getValuesFromWorkbookData(VERY_HIDDEN_SHEET_PATH);
998
        
999
        for(Object o: veryHiddedSheetIdxAry){
1000
            int index = (Integer.parseInt(o.toString())-1);
1001
            if(index == sheetIx)return SheetVisibility.VERY_HIDDEN;
1002
        }
1003
        
1004
        throw new IllegalArgumentException("Invalid sheet index");
1005
        
1006
        
1007
    }
1008
1009
    /**
1010
     * <pre>
1011
     * Not supported right now, as StreamedWorkbook
1012
     * supports only reading.
1013
     * </pre>
1014
     * @exception UnsupportedOperationException
1015
     */ 
1016
    @NotImplemented
1017
    public void setSheetVisibility(int sheetIx, SheetVisibility visibility) {
1018
        throw new UnsupportedOperationException("Not supported due to memory footprint");
1019
    }
1020
1021
    /**
1022
     * <pre>
1023
     * Not supported right now, as StreamedWorkbook
1024
     * supports only reading.
1025
     * </pre>
1026
     * @exception UnsupportedOperationException
1027
     */ 
1028
    @NotImplemented
1029
    public int addOlePackage(byte[] oleData, String label, String fileName,
1030
            String command) throws IOException {
1031
        throw new UnsupportedOperationException("Not supported due to memory footprint");
1032
    }
1033
    
1034
    /**
1035
     * Strictly for reading any specific value from any node in workbook.xml
1036
     * DOM Parser is used here assuming that workbook.xml will never contribute 
1037
     * towards the size of excel file.
1038
     *
1039
     * @param xml
1040
     * @param xpathQuery
1041
     * @return Object[]
1042
     * @throws Exception
1043
     */
1044
    private Object[] getValuesFromWorkbookData(String xpathQuery){
1045
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
1046
        List<String> valueAry = new ArrayList<String>();
1047
        DocumentBuilder builder;
1048
        Document doc = null;
1049
        NodeList nodeList = null;
1050
        try{
1051
            builder = factory.newDocumentBuilder();
1052
            doc = builder.parse(globalReader.getWorkbookData());
1053
            XPathFactory xPathfactory = XPathFactory.newInstance();
1054
            XPath xpath = xPathfactory.newXPath();
1055
            doc.normalize();
1056
    
1057
            
1058
            XPathExpression xPathExpr = xpath.compile(xpathQuery);
1059
            nodeList = (NodeList)xPathExpr.evaluate(doc, XPathConstants.NODESET);
1060
1061
            for(int i=0; i<nodeList.getLength(); i++){
1062
                valueAry.add(nodeList.item(i).getNodeValue());
1063
            }
1064
        }catch(Exception e){
1065
            logger.log(POILogger.ERROR, "Exception while reading the workbook.");
1066
        }
1067
        
1068
        return valueAry.toArray();
1069
    }
1070
}
(-)a/src/ooxml/testcases/org/apache/poi/xssf/streaming/reader/TestStreamedWorkbook.java (+895 lines)
Line 0 Link Here
1
/*
2
 *  ====================================================================
3
 *    Licensed to the Apache Software Foundation (ASF) under one or more
4
 *    contributor license agreements.  See the NOTICE file distributed with
5
 *    this work for additional information regarding copyright ownership.
6
 *    The ASF licenses this file to You under the Apache License, Version 2.0
7
 *    (the "License"); you may not use this file except in compliance with
8
 *    the License.  You may obtain a copy of the License at
9
 *
10
 *        http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 *    Unless required by applicable law or agreed to in writing, software
13
 *    distributed under the License is distributed on an "AS IS" BASIS,
14
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 *    See the License for the specific language governing permissions and
16
 *    limitations under the License.
17
 * ====================================================================
18
 */
19
package org.apache.poi.xssf.streaming.reader;
20
21
import static org.junit.Assert.assertEquals;
22
import static org.junit.Assert.fail;
23
24
import java.io.File;
25
import java.util.ArrayList;
26
import java.util.Iterator;
27
import java.util.List;
28
29
import org.apache.poi.POIDataSamples;
30
import org.apache.poi.ss.usermodel.Cell;
31
import org.apache.poi.ss.usermodel.Row;
32
import org.apache.poi.ss.usermodel.Sheet;
33
import org.apache.poi.ss.usermodel.Workbook;
34
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
35
import org.junit.Test;
36
37
38
public class TestStreamedWorkbook{
39
    
40
41
   @Test
42
    public void testInvalidFilePath() throws Exception{
43
       StreamedWorkbook workbook = null;
44
       try {
45
            workbook = new StreamedWorkbook(null);
46
            fail("expected exception");
47
        } catch (Exception e) {
48
            assertEquals("No sheets found", e.getMessage());
49
        }
50
        
51
        if(workbook != null)workbook.close();
52
        
53
    }
54
    
55
    @Test
56
    public void testInvalidFile() throws Exception{ 
57
        POIDataSamples files = POIDataSamples.getSpreadSheetInstance();
58
        File f= files.getFile("InvalidFile.txt");
59
        StreamedWorkbook workbook = null;
60
        try {
61
        
62
            workbook = new StreamedWorkbook(f.getAbsolutePath());
63
            workbook.getSheetIterator();
64
        } catch (Exception e) {
65
            assertEquals("No valid entries or contents found, this is not a valid OOXML (Office Open XML) file", e.getMessage());
66
        }
67
        
68
        if(workbook != null)workbook.close();
69
    }
70
    
71
   
72
    @Test
73
    public void testSheetCount() throws Exception{
74
        POIDataSamples files = POIDataSamples.getSpreadSheetInstance();
75
        File f= files.getFile("SpreadSheetSample04022017.xlsx");
76
        StreamedWorkbook streamedWorkbook = new StreamedWorkbook(f.getAbsolutePath());
77
        Workbook workbook = new XSSFWorkbook(f);
78
        int streamedSheetcount = 0;
79
        int count=0;
80
        
81
        try {
82
            Iterator<StreamedSheet> streamedSheetIterator = streamedWorkbook.getSheetIterator();
83
            
84
            while(streamedSheetIterator.hasNext()){
85
                streamedSheetIterator.next();
86
                streamedSheetcount++;
87
            }
88
            
89
            Iterator<Sheet> sheetIterator = workbook.sheetIterator();
90
            
91
            while(sheetIterator.hasNext()){
92
                sheetIterator.next();
93
                count++;
94
            }
95
            
96
            assertEquals(count, streamedSheetcount);
97
        } catch (Exception e) {
98
            
99
        }
100
        
101
        streamedWorkbook.close();
102
        workbook.close();
103
       
104
    }
105
    
106
    @Test
107
    public void testTotalNumberOfSheets() throws Exception{
108
        POIDataSamples files = POIDataSamples.getSpreadSheetInstance();
109
        File f= files.getFile("SpreadSheetSample04022017.xlsx");
110
        StreamedWorkbook streamedWorkbook = new StreamedWorkbook(f.getAbsolutePath());
111
        Workbook workbook = new XSSFWorkbook(f);
112
        
113
        try {
114
            int sheetCount = workbook.getNumberOfSheets();
115
            int streamedSheetCount = streamedWorkbook.getNumberOfSheets();
116
            
117
            assertEquals(sheetCount, streamedSheetCount);
118
        } catch (Exception e) {
119
        }
120
       
121
        workbook.close();
122
        streamedWorkbook.close();
123
    }
124
    
125
    @Test
126
    public void testTotalRowCount() throws Exception{
127
        POIDataSamples files = POIDataSamples.getSpreadSheetInstance();
128
        File f= files.getFile("SpreadSheetSample04022017.xlsx");
129
        StreamedWorkbook streamedWorkbook = new StreamedWorkbook(f.getAbsolutePath());
130
        Workbook workbook = new XSSFWorkbook(f);
131
        int streamedSheetCount = 0;
132
        
133
        long streamedRowCount = 0;
134
        
135
        Iterator<StreamedSheet> streamedSheetIterator = streamedWorkbook.getSheetIterator();
136
        
137
        while((streamedSheetIterator.hasNext()) && (streamedSheetCount == 0)){
138
            StreamedSheet sheet = streamedSheetIterator.next();
139
            
140
            Iterator<StreamedRow> rows = sheet.getAllRows();
141
            
142
            while(rows.hasNext()){
143
                rows.next();
144
                streamedRowCount++;
145
            }
146
            
147
            streamedSheetCount++;
148
        }
149
        
150
        int sheetCount= 0;
151
        int rowCount = 0;
152
        Iterator<Sheet> sheetIterator = workbook.sheetIterator();
153
        while(sheetIterator.hasNext() && sheetCount ==0){
154
            Sheet sheet = sheetIterator.next();
155
            Iterator<Row> rowIterator = sheet.iterator();
156
            
157
            while(rowIterator.hasNext()){
158
                rowIterator.next();
159
                rowCount++;
160
            }
161
            
162
            sheetCount++;
163
        }
164
        
165
        assertEquals(rowCount, streamedRowCount);
166
        
167
        streamedWorkbook.close();
168
        workbook.close();
169
    }
170
    
171
    @Test
172
    public void testNRowCount() throws Exception{
173
        POIDataSamples files = POIDataSamples.getSpreadSheetInstance();
174
        File f= files.getFile("SpreadSheetSample04022017.xlsx");
175
        StreamedWorkbook workbook = new StreamedWorkbook(f.getAbsolutePath());
176
        
177
        long count = 0;
178
        int sheetCount = 0;
179
        
180
        Iterator<StreamedSheet> sheetIterator = workbook.getSheetIterator();
181
        
182
        while((sheetIterator.hasNext()) && (sheetCount == 0)){
183
            StreamedSheet sheet = sheetIterator.next();
184
            
185
            Iterator<StreamedRow> rows = sheet.getNRows(4);
186
            
187
            while(rows.hasNext()){
188
                rows.next();
189
                count++;
190
            }
191
            
192
            assertEquals(4, count);
193
            sheetCount++;
194
        }
195
        
196
        workbook.close();
197
    }
198
    
199
    @Test
200
    public void testTotalCellCount() throws Exception{
201
        POIDataSamples files = POIDataSamples.getSpreadSheetInstance();
202
        File f= files.getFile("SpreadSheetSample04022017.xlsx");
203
        StreamedWorkbook streamedWorkbook = new StreamedWorkbook(f.getAbsolutePath());
204
        Workbook workbook = new XSSFWorkbook(f);
205
        int streamedSheetCount = 0;
206
        long streamedCellCount = 0;
207
        long cellCount = 0;
208
        
209
        Iterator<StreamedSheet> streamedSheetIterator = streamedWorkbook.getSheetIterator();
210
        
211
        while((streamedSheetIterator.hasNext()) && (streamedSheetCount == 0)){
212
            StreamedSheet streamedSheet = streamedSheetIterator.next();
213
            
214
            Iterator<StreamedRow> streamedRows = streamedSheet.getAllRows();
215
            
216
            while(streamedRows.hasNext()){
217
                StreamedRow streamedRow = streamedRows.next();
218
                
219
                Iterator<StreamedCell> streamedCellIterator = streamedRow.getCellIterator();
220
                
221
                while(streamedCellIterator.hasNext()){
222
                    streamedCellIterator.next();
223
                    streamedCellCount++;
224
                }
225
                
226
            }
227
            
228
            streamedSheetCount++;
229
        }
230
        
231
        int sheetCount = 0;
232
        Iterator<Sheet> sheetIterator = workbook.sheetIterator();
233
        
234
        while((sheetIterator.hasNext()) && (sheetCount == 0)){
235
            Sheet sheet = sheetIterator.next();
236
            
237
            Iterator<Row> rowIterator = sheet.iterator();
238
            while(rowIterator.hasNext()){
239
                Row row = rowIterator.next();
240
                
241
                Iterator<Cell> cellIterator = row.cellIterator();
242
                
243
                while(cellIterator.hasNext()){
244
                    cellIterator.next();
245
                    cellCount++;
246
                }
247
            }
248
            
249
            sheetCount++;
250
        }
251
252
        assertEquals(cellCount, streamedCellCount);
253
        
254
        streamedWorkbook.close();
255
        workbook.close();
256
    }
257
    
258
    
259
    @Test
260
    public void testStartingRowAndCellNumber() throws Exception{
261
        POIDataSamples files = POIDataSamples.getSpreadSheetInstance();
262
        File f= files.getFile("SpreadSheetSample04022017.xlsx");
263
        StreamedWorkbook streamedWorkbook = new StreamedWorkbook(f.getAbsolutePath());
264
        Workbook workbook = new XSSFWorkbook(f);
265
        
266
        List<Short> workbookStartingCellNumbers = new ArrayList<Short>();
267
        List<Short> streamedWorkbookStartingCellNumbers = new ArrayList<Short>();
268
        
269
        int workbookStartingRowNum = 0;
270
        int streamedWorkbookStartingRowNumber = 0;
271
        
272
        Sheet sheet = workbook.getSheetAt(0);
273
        Iterator<Row> rowIterator = sheet.iterator();
274
        
275
        int workbookRowCount = 0;
276
        
277
        while(rowIterator.hasNext()){
278
            Row row = rowIterator.next();
279
            if(workbookRowCount == 0){
280
                workbookStartingRowNum = row.getRowNum();
281
                workbookRowCount++;
282
            }
283
            
284
            if(row != null)
285
            workbookStartingCellNumbers.add(row.getFirstCellNum());
286
            
287
        }
288
        
289
        StreamedSheet streamedSheet = (StreamedSheet)streamedWorkbook.getSheetAt(0);
290
        Iterator<StreamedRow> streamedRowIterator = streamedSheet.getAllRows();
291
        int streamedWorkbookRowCount = 0;
292
        
293
        while(streamedRowIterator.hasNext()){
294
            StreamedRow row = streamedRowIterator.next();
295
            if(streamedWorkbookRowCount == 0){
296
                streamedWorkbookStartingRowNumber = row.getRowNum();
297
                streamedWorkbookRowCount++;
298
            }
299
            
300
            if(row != null)
301
                streamedWorkbookStartingCellNumbers.add(row.getFirstCellNum());
302
        }
303
        
304
        assertEquals(workbookStartingRowNum, streamedWorkbookStartingRowNumber);
305
        assertEquals(workbookStartingCellNumbers, streamedWorkbookStartingCellNumbers);
306
        
307
        workbook.close();
308
        streamedWorkbook.close();
309
    }
310
    
311
    @Test
312
    public void testSheetData() throws Exception{
313
        POIDataSamples files = POIDataSamples.getSpreadSheetInstance();
314
        File f= files.getFile("SpreadSheetSample04022017.xlsx");
315
        StreamedWorkbook workbook = new StreamedWorkbook(f.getAbsolutePath());
316
        int sheetCount = 0;
317
        
318
        
319
        Iterator<StreamedSheet> sheetIterator = workbook.getSheetIterator();
320
        
321
        while((sheetIterator.hasNext()) && (sheetCount == 0)){
322
            int rowCount = 0;
323
            
324
            StreamedSheet sheet = sheetIterator.next();
325
            
326
            Iterator<StreamedRow> rows = sheet.getAllRows();
327
            
328
            while(rows.hasNext()){
329
                
330
                StreamedRow row = rows.next();
331
                
332
                int cellCount = 0;
333
                
334
                Iterator<StreamedCell> cellIterator = row.getCellIterator();
335
                
336
                while(cellIterator.hasNext()){
337
                    StreamedCell cell = cellIterator.next();
338
                    if(rowCount == 1){
339
                        
340
                        if(cellCount == 0){
341
                            assertEquals("1", cell.getValue());
342
                        }else if(cellCount == 1){
343
                            assertEquals("Item1", cell.getValue());
344
                        }else if(cellCount == 2){
345
                            assertEquals("201", cell.getValue());
346
                        }else if(cellCount == 3){
347
                            assertEquals("100.11", cell.getValue());
348
                        }else if(cellCount == 4){
349
                            assertEquals("TRUE", cell.getValue());
350
                        }else if(cellCount == 5){
351
                            assertEquals("04/02/1917", cell.getValue());
352
                        }else if(cellCount == 6){
353
                            assertEquals("90.11", cell.getValue());
354
                        }
355
                    }else if(rowCount == 3){
356
                        if(cellCount == 4){
357
                            assertEquals(null, cell.getValue());
358
                        }
359
                    }
360
                    
361
                    cellCount++;
362
                    
363
                }
364
                
365
                
366
                rowCount++;
367
                
368
            }
369
            
370
            sheetCount++;
371
        }
372
        
373
        workbook.close();
374
    }
375
    
376
    @Test
377
    public void testBatchData() throws Exception{
378
        
379
        POIDataSamples files = POIDataSamples.getSpreadSheetInstance();
380
        File f= files.getFile("SpreadSheetSample04022017.xlsx");
381
        StreamedWorkbook workbook = new StreamedWorkbook(f.getAbsolutePath());
382
        int sheetCount = 0;
383
        
384
        
385
        Iterator<StreamedSheet> sheetIterator = workbook.getSheetIterator();
386
        
387
        while(sheetIterator.hasNext()){
388
            
389
            StreamedSheet sheet = sheetIterator.next();
390
            
391
            if(sheetCount == 1){
392
                Iterator<StreamedRow> rows = sheet.getNRows(1);
393
                
394
                while(rows.hasNext()){
395
                    StreamedRow row = rows.next();
396
                    assertEquals("Row Number:0 --> Item | item description | Strore | Price | Promotion applied | MFD | Discount rate |", row.toString().trim());
397
                }
398
                
399
                
400
                rows = sheet.getNRows(4);
401
                
402
                while(rows.hasNext()){
403
                    StreamedRow row = rows.next();
404
                    assertEquals("Row Number:1 --> 1 | Item1 | 201 | 100.11 | TRUE | 04/02/1917 | 90.11 |", row.toString().trim());
405
                    row = rows.next();
406
                    assertEquals("Row Number:2 --> 2 | Item2 | 202 | 101.11 | TRUE | 05/02/1917 | 91.11 |", row.toString().trim());
407
                    row = rows.next();
408
                    assertEquals("Row Number:3 --> 3 | Item3 | 203 | 102.11 | TRUE | 06/02/1917 | 92.11 |", row.toString().trim());
409
                    row = rows.next();
410
                    assertEquals("Row Number:4 --> 4 | Item4 | 204 | 103.11 | TRUE | 07/02/1917 | 93.11 |", row.toString().trim());
411
                }
412
                
413
                
414
                
415
                rows = sheet.getNRows(4);
416
                
417
                while(rows.hasNext()){
418
                    StreamedRow row = rows.next();
419
                    assertEquals("Row Number:5 --> 5 | Item5 | 205 | 104.11 | TRUE | 08/02/1917 | 94.11 |", row.toString().trim());
420
                    row = rows.next();
421
                    assertEquals("Row Number:6 --> 6 | Item6 | 206 | 105.11 | TRUE | 09/02/1917 | 95.11 |", row.toString().trim());
422
                    row = rows.next();
423
                    assertEquals("Row Number:7 --> 7 | Item7 | 207 | 106.11 | TRUE | 10/02/1917 | 96.11 |", row.toString().trim());
424
                    row = rows.next();
425
                    assertEquals("Row Number:8 --> 8 | Item8 | 208 | 107.11 | FALSE | 11/02/1917 | 97.11 |", row.toString().trim());
426
                }
427
                
428
            }
429
            
430
431
            sheetCount++;
432
            
433
        }
434
        
435
        workbook.close();
436
        
437
    }
438
    
439
    
440
    @Test
441
    public void testGetCell() throws Exception{
442
        POIDataSamples files = POIDataSamples.getSpreadSheetInstance();
443
        File f= files.getFile("SpreadSheetSample04022017.xlsx");
444
        StreamedWorkbook workbook = new StreamedWorkbook(f.getAbsolutePath());
445
        int sheetCount = 0;
446
        
447
        
448
        Iterator<StreamedSheet> sheetIterator = workbook.getSheetIterator();
449
        
450
        while((sheetIterator.hasNext()) && (sheetCount == 0)){
451
            
452
            StreamedSheet sheet = sheetIterator.next();
453
            
454
            Iterator<StreamedRow> rows = sheet.getAllRows();
455
            
456
            while(rows.hasNext()){
457
                
458
                StreamedRow row = rows.next();
459
                
460
                if(row.getRowNum() == 3){
461
                    StreamedCell cell = (StreamedCell)row.getCell(5);
462
                    assertEquals("06/02/1917", cell.getValue());
463
                    
464
                    try{
465
                        cell = (StreamedCell)row.getCell(10);
466
                    }catch(Exception exception){
467
                        assertEquals(true, exception instanceof IndexOutOfBoundsException);
468
                    }
469
                }
470
                
471
472
            }
473
            
474
            sheetCount++;
475
        }
476
        
477
        workbook.close();
478
    }
479
    
480
    
481
    @Test
482
    public void testGetFirstAndLastCellNum() throws Exception{
483
        POIDataSamples files = POIDataSamples.getSpreadSheetInstance();
484
        File f= files.getFile("SpreadSheetSample04022017.xlsx");
485
        StreamedWorkbook workbook = new StreamedWorkbook(f.getAbsolutePath());
486
        int sheetCount = 0;
487
        
488
        
489
        Iterator<StreamedSheet> sheetIterator = workbook.getSheetIterator();
490
        
491
        while((sheetIterator.hasNext()) && (sheetCount == 0)){
492
            
493
            StreamedSheet sheet = sheetIterator.next();
494
            
495
            Iterator<StreamedRow> rows = sheet.getAllRows();
496
            
497
            while(rows.hasNext()){
498
                
499
                StreamedRow row = rows.next();
500
                
501
                if(row.getRowNum() == 3){
502
                    StreamedCell cell = (StreamedCell)row.getCell(row.getFirstCellNum());
503
                    assertEquals("3", cell.getValue());
504
                    assertEquals("3", cell.getStringCellValue());
505
                    
506
                    cell = (StreamedCell)row.getCell(row.getLastCellNum()-1);
507
                    assertEquals("92.11", cell.getValue());
508
                    assertEquals("92.11", cell.getStringCellValue());
509
                }
510
            }
511
            
512
            sheetCount++;
513
        }
514
        
515
        workbook.close();
516
    }
517
    
518
    @Test
519
    public void testReopenClosedWorkbook(){
520
        
521
        try{
522
            POIDataSamples files = POIDataSamples.getSpreadSheetInstance();
523
            File f= files.getFile("SpreadSheetSample04022017.xlsx");
524
            StreamedWorkbook workbook = new StreamedWorkbook(f.getAbsolutePath());
525
            
526
            workbook.close();
527
            
528
            Iterator<StreamedSheet> sheetIterator = workbook.getSheetIterator();
529
        }catch(Exception e){
530
            assertEquals("Workbook already closed", e.getMessage());
531
        }
532
            
533
534
    }
535
    
536
    @Test
537
    public void testGetActiveSheetIndex() throws Exception{
538
        POIDataSamples files = POIDataSamples.getSpreadSheetInstance();
539
        File f= files.getFile("SpreadSheetSample04022017.xlsx");
540
        StreamedWorkbook streamedWorkbook = new StreamedWorkbook(f.getAbsolutePath());
541
        
542
        Workbook workbook = new XSSFWorkbook(f);
543
        
544
        assertEquals(workbook.getActiveSheetIndex(), streamedWorkbook.getActiveSheetIndex());
545
        streamedWorkbook.close();
546
        workbook.close();
547
    }
548
    
549
    @Test
550
    public void testGetSheetNameWithSheetIndex() throws Exception{
551
        POIDataSamples files = POIDataSamples.getSpreadSheetInstance();
552
        File f= files.getFile("SpreadSheetSample04022017.xlsx");
553
        StreamedWorkbook streamedWorkbook = new StreamedWorkbook(f.getAbsolutePath());
554
        
555
        Workbook workbook = new XSSFWorkbook(f);
556
        
557
        assertEquals(workbook.getSheetName(1), streamedWorkbook.getSheetName(1));
558
        streamedWorkbook.close();
559
        workbook.close();
560
    }
561
    
562
    @Test
563
    public void testGetSheetIndex() throws Exception{
564
        POIDataSamples files = POIDataSamples.getSpreadSheetInstance();
565
        File f= files.getFile("SpreadSheetSample04022017.xlsx");
566
        StreamedWorkbook streamedWorkbook = new StreamedWorkbook(f.getAbsolutePath());
567
        
568
        Workbook workbook = new XSSFWorkbook(f);
569
        
570
        assertEquals(workbook.getSheetIndex("Sheet3"), streamedWorkbook.getSheetIndex("Sheet3"));
571
        streamedWorkbook.close();
572
        workbook.close();
573
    }
574
    
575
    @Test
576
    public void testGetFirstVisibleTab() throws Exception{
577
        POIDataSamples files = POIDataSamples.getSpreadSheetInstance();
578
        File f= files.getFile("SpreadSheetSample04022017.xlsx");
579
        StreamedWorkbook streamedWorkbook = new StreamedWorkbook(f.getAbsolutePath());
580
        
581
        Workbook workbook = new XSSFWorkbook(f);
582
        
583
        assertEquals(workbook.getFirstVisibleTab(), streamedWorkbook.getFirstVisibleTab());
584
        streamedWorkbook.close();
585
        workbook.close();
586
    }
587
    
588
    @Test
589
    public void testGetSheetName() throws Exception{
590
        POIDataSamples files = POIDataSamples.getSpreadSheetInstance();
591
        File f= files.getFile("SpreadSheetSample04022017.xlsx");
592
        StreamedWorkbook streamedWorkbook = new StreamedWorkbook(f.getAbsolutePath());
593
        
594
        List<String> workbookSheetNames = new ArrayList<String>();
595
        List<String> streamedWorkbookSheetNames = new ArrayList<String>();
596
        
597
        Workbook workbook = new XSSFWorkbook(f);
598
        
599
        Iterator<Sheet> sheetIterator = workbook.sheetIterator();
600
        
601
        while(sheetIterator.hasNext()){
602
            workbookSheetNames.add(sheetIterator.next().getSheetName());
603
        }
604
        
605
        
606
        
607
        Iterator<StreamedSheet> streamedSheetIterator = streamedWorkbook.getSheetIterator();
608
        
609
        while(streamedSheetIterator.hasNext()){
610
            streamedWorkbookSheetNames.add(streamedSheetIterator.next().getSheetName());
611
        }
612
        
613
        
614
        assertEquals(workbookSheetNames, streamedWorkbookSheetNames);
615
        
616
        streamedWorkbook.close();
617
        workbook.close();
618
    }
619
    
620
    @Test
621
    public void testIsSheetHidden() throws Exception{
622
        POIDataSamples files = POIDataSamples.getSpreadSheetInstance();
623
        File f= files.getFile("SpreadSheetSample04022017.xlsx");
624
        StreamedWorkbook streamedWorkbook = new StreamedWorkbook(f.getAbsolutePath());
625
        Workbook workbook = new XSSFWorkbook(f);
626
627
        
628
        assertEquals(workbook.isSheetHidden(2), streamedWorkbook.isSheetHidden(2));
629
        assertEquals(workbook.isSheetHidden(1), streamedWorkbook.isSheetHidden(1));
630
        
631
        streamedWorkbook.close();
632
        workbook.close();
633
        
634
    }
635
    
636
    @Test
637
    public void testGetSheetVisibility() throws Exception{
638
        POIDataSamples files = POIDataSamples.getSpreadSheetInstance();
639
        File f= files.getFile("SpreadSheetSample04022017.xlsx");
640
        StreamedWorkbook streamedWorkbook = new StreamedWorkbook(f.getAbsolutePath());
641
        Workbook workbook = new XSSFWorkbook(f);
642
643
        
644
        assertEquals(workbook.getSheetVisibility(2), streamedWorkbook.getSheetVisibility(2));
645
        assertEquals(workbook.getSheetVisibility(1), streamedWorkbook.getSheetVisibility(1));
646
        
647
        streamedWorkbook.close();
648
        workbook.close();
649
        
650
    }
651
    
652
    @Test
653
    public void testGetSheet() throws Exception{
654
        POIDataSamples files = POIDataSamples.getSpreadSheetInstance();
655
        File f= files.getFile("SpreadSheetSample04022017.xlsx");
656
        StreamedWorkbook streamedWorkbook = new StreamedWorkbook(f.getAbsolutePath());
657
        Workbook workbook = new XSSFWorkbook(f);
658
        
659
        Sheet sheet = workbook.getSheet("Sheet2");
660
        Sheet streamedSheet = streamedWorkbook.getSheet("Sheet2");
661
662
        assertEquals(sheet.getSheetName(), streamedSheet.getSheetName());
663
        
664
        streamedWorkbook.close();
665
        workbook.close();
666
        
667
    }
668
    
669
    @Test(expected=NullPointerException.class)
670
    public void testGetSheetAfterClose() throws Exception{
671
        POIDataSamples files = POIDataSamples.getSpreadSheetInstance();
672
        File f= files.getFile("SpreadSheetSample04022017.xlsx");
673
        StreamedWorkbook streamedWorkbook = new StreamedWorkbook(f.getAbsolutePath());
674
        streamedWorkbook.close();
675
        Sheet streamedSheet = streamedWorkbook.getSheet("Sheet2");
676
        System.out.println(streamedSheet.getSheetName());
677
    }
678
    
679
    @Test
680
    public void testGetSheetAt() throws Exception{
681
        POIDataSamples files = POIDataSamples.getSpreadSheetInstance();
682
        File f= files.getFile("SpreadSheetSample04022017.xlsx");
683
        StreamedWorkbook streamedWorkbook = new StreamedWorkbook(f.getAbsolutePath());
684
        Workbook workbook = new XSSFWorkbook(f);
685
        
686
        Sheet sheet = workbook.getSheetAt(0);
687
        Sheet streamedSheet = streamedWorkbook.getSheetAt(0);
688
689
        assertEquals(sheet.getSheetName(), streamedSheet.getSheetName());
690
        
691
        streamedWorkbook.close();
692
        workbook.close();
693
        
694
    }
695
    
696
    @Test(expected=NullPointerException.class)
697
    public void testGetSheetAtAfterClose() throws Exception{
698
        POIDataSamples files = POIDataSamples.getSpreadSheetInstance();
699
        File f= files.getFile("SpreadSheetSample04022017.xlsx");
700
        StreamedWorkbook streamedWorkbook = new StreamedWorkbook(f.getAbsolutePath());
701
        streamedWorkbook.close();
702
        
703
        Sheet streamedSheet = streamedWorkbook.getSheetAt(0);
704
        System.out.println(streamedSheet.getSheetName());
705
706
    }
707
    
708
    
709
    @Test(expected=NullPointerException.class)
710
    public void testGetSheetException() throws Exception{
711
        POIDataSamples files = POIDataSamples.getSpreadSheetInstance();
712
        File f= files.getFile("SpreadSheetSample04022017.xlsx");
713
        StreamedWorkbook streamedWorkbook = new StreamedWorkbook(f.getAbsolutePath());
714
        
715
        Sheet sheet = streamedWorkbook.getSheet("Sheet200");
716
        
717
        sheet.getSheetName();
718
        
719
        streamedWorkbook.close();
720
        
721
    }
722
    
723
    @Test
724
    public void testGetFirstCellNumber() throws Exception{
725
        POIDataSamples files = POIDataSamples.getSpreadSheetInstance();
726
        File f= files.getFile("SpreadSheetSample04022017.xlsx");
727
        StreamedWorkbook streamedWorkbook = new StreamedWorkbook(f.getAbsolutePath());
728
        Workbook workbook = new XSSFWorkbook(f);
729
        
730
        List<Short> workbookFirstCellNumList = new ArrayList<Short>();
731
        List<Short> sworkbookFirstCellNumList = new ArrayList<Short>();
732
        
733
        Iterator<Sheet> workbookSheetIterator = workbook.iterator();
734
        while(workbookSheetIterator.hasNext()){
735
            Sheet sheet = workbookSheetIterator.next();
736
            Iterator<Row> rowIterator = sheet.iterator();
737
            while(rowIterator.hasNext()){
738
                Row row = rowIterator.next();
739
                workbookFirstCellNumList.add(row.getFirstCellNum());
740
            }
741
        }
742
        
743
        
744
        Iterator<StreamedSheet> sworkbookSheetIterator = streamedWorkbook.getSheetIterator();
745
        while(sworkbookSheetIterator.hasNext()){
746
            StreamedSheet sheet = sworkbookSheetIterator.next();
747
            Iterator<StreamedRow> rowIterator = sheet.getAllRows();
748
            while(rowIterator.hasNext()){
749
                Row row = rowIterator.next();
750
                sworkbookFirstCellNumList.add(row.getFirstCellNum());
751
            }
752
        }
753
        
754
        
755
        assertEquals(workbookFirstCellNumList, sworkbookFirstCellNumList);
756
        
757
        streamedWorkbook.close();
758
        workbook.close();
759
        
760
    }
761
    
762
    @Test
763
    public void testGetLastCellNumber() throws Exception{
764
        POIDataSamples files = POIDataSamples.getSpreadSheetInstance();
765
        File f= files.getFile("SpreadSheetSample04022017.xlsx");
766
        StreamedWorkbook streamedWorkbook = new StreamedWorkbook(f.getAbsolutePath());
767
        Workbook workbook = new XSSFWorkbook(f);
768
        
769
        List<Short> workbookLastCellNumList = new ArrayList<Short>();
770
        List<Short> sworkbookLastCellNumList = new ArrayList<Short>();
771
        
772
        Iterator<Sheet> workbookSheetIterator = workbook.iterator();
773
        while(workbookSheetIterator.hasNext()){
774
            Sheet sheet = workbookSheetIterator.next();
775
            Iterator<Row> rowIterator = sheet.iterator();
776
            while(rowIterator.hasNext()){
777
                Row row = rowIterator.next();
778
                workbookLastCellNumList.add(row.getLastCellNum());
779
            }
780
        }
781
        
782
        
783
        Iterator<StreamedSheet> sworkbookSheetIterator = streamedWorkbook.getSheetIterator();
784
        while(sworkbookSheetIterator.hasNext()){
785
            StreamedSheet sheet = sworkbookSheetIterator.next();
786
            Iterator<StreamedRow> rowIterator = sheet.getAllRows();
787
            while(rowIterator.hasNext()){
788
                Row row = rowIterator.next();
789
                sworkbookLastCellNumList.add(row.getLastCellNum());
790
            }
791
        }
792
        
793
        
794
        assertEquals(workbookLastCellNumList, sworkbookLastCellNumList);
795
        
796
        streamedWorkbook.close();
797
        workbook.close();
798
        
799
    }
800
    
801
    @Test
802
    public void testGetPhysicalNumOfCells() throws Exception{
803
        POIDataSamples files = POIDataSamples.getSpreadSheetInstance();
804
        File f= files.getFile("SpreadSheetSample04022017.xlsx");
805
        StreamedWorkbook streamedWorkbook = new StreamedWorkbook(f.getAbsolutePath());
806
        Workbook workbook = new XSSFWorkbook(f);
807
        
808
        List<Integer> workbookPhysicalCellNums = new ArrayList<Integer>();
809
        List<Integer> sworkbookPhysicalCellNums = new ArrayList<Integer>();
810
        
811
        Iterator<Sheet> workbookSheetIterator = workbook.iterator();
812
        while(workbookSheetIterator.hasNext()){
813
            Sheet sheet = workbookSheetIterator.next();
814
            Iterator<Row> rowIterator = sheet.iterator();
815
            while(rowIterator.hasNext()){
816
                Row row = rowIterator.next();
817
                workbookPhysicalCellNums.add(row.getPhysicalNumberOfCells());
818
            }
819
        }
820
        
821
        
822
        Iterator<StreamedSheet> sworkbookSheetIterator = streamedWorkbook.getSheetIterator();
823
        while(sworkbookSheetIterator.hasNext()){
824
            StreamedSheet sheet = sworkbookSheetIterator.next();
825
            Iterator<StreamedRow> rowIterator = sheet.getAllRows();
826
            while(rowIterator.hasNext()){
827
                Row row = rowIterator.next();
828
                sworkbookPhysicalCellNums.add(row.getPhysicalNumberOfCells());
829
            }
830
        }
831
        
832
        
833
        assertEquals(workbookPhysicalCellNums, sworkbookPhysicalCellNums);
834
        
835
        streamedWorkbook.close();
836
        workbook.close();
837
        
838
    }
839
    
840
    
841
    @Test
842
    public void testGetColumnIndex() throws Exception{
843
        POIDataSamples files = POIDataSamples.getSpreadSheetInstance();
844
        File f= files.getFile("SpreadSheetSample04022017.xlsx");
845
        StreamedWorkbook streamedWorkbook = new StreamedWorkbook(f.getAbsolutePath());
846
        Workbook workbook = new XSSFWorkbook(f);
847
        
848
        List<Integer> workbookColIndexList = new ArrayList<Integer>();
849
        List<Integer> sworkbookColIndexList = new ArrayList<Integer>();
850
        
851
        
852
        
853
        Iterator<Sheet> workbookSheetIterator = workbook.iterator();
854
        while(workbookSheetIterator.hasNext()){
855
            Sheet sheet = workbookSheetIterator.next();
856
            Iterator<Row> rowIterator = sheet.iterator();
857
            while(rowIterator.hasNext()){
858
                Row row = rowIterator.next();
859
                
860
                Iterator<Cell> cellIterator = row.cellIterator();
861
                while(cellIterator.hasNext()){
862
                    Cell cell = cellIterator.next();
863
                    workbookColIndexList.add(cell.getColumnIndex());
864
                }
865
            }
866
        }
867
        
868
        
869
        
870
        Iterator<StreamedSheet> sworkbookSheetIterator = streamedWorkbook.getSheetIterator();
871
        while(sworkbookSheetIterator.hasNext()){
872
            StreamedSheet sheet = sworkbookSheetIterator.next();
873
            Iterator<StreamedRow> rowIterator = sheet.getAllRows();
874
            while(rowIterator.hasNext()){
875
                StreamedRow row = rowIterator.next();
876
                
877
                Iterator<StreamedCell> cellIterator = row.getCellIterator();
878
                while(cellIterator.hasNext()){
879
                    Cell cell = cellIterator.next();
880
                    sworkbookColIndexList.add(cell.getColumnIndex());
881
                }
882
            }
883
        }
884
        
885
        
886
        assertEquals(workbookColIndexList, sworkbookColIndexList);
887
        
888
        streamedWorkbook.close();
889
        workbook.close();
890
        
891
    }
892
    
893
    
894
    
895
}

Return to bug 60707