-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathXlsxLineByLineReader.js
More file actions
62 lines (50 loc) · 2.15 KB
/
XlsxLineByLineReader.js
File metadata and controls
62 lines (50 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
var xlsxLineByLineReader = function(doc){
var File = java.io.File;
var FileInputStream = java.io.FileInputStream;
var Iterator = java.util.Iterator;
var ZipSecureFile = org.apache.poi.openxml4j.util.ZipSecureFile;
var Cell = org.apache.poi.ss.usermodel.Cell;
var Row = org.apache.poi.ss.usermodel.Row;
var XSSFSheet = org.apache.poi.xssf.usermodel.XSSFSheet;
var XSSFWorkbook = org.apache.poi.xssf.usermodel.XSSFWorkbook;
var e = java.lang.Exception;
try{
ZipSecureFile.setMinInflateRatio(-1.0);
var file = new FileInputStream(new File("/Users/kevin/Dropbox/IBM_Timecard_CAR_Kevin Cowan SVS_weekending 9-26-15.xlsx"));
//Create Workbook instance holding reference to .xlsx file
var workbook = new XSSFWorkbook(file);
//Get first/desired sheet from the workbook
var sheet = workbook.getSheetAt(0);
//Iterate through each rows one by one
var rowIterator = sheet.iterator();
while (rowIterator.hasNext())
{
var row = rowIterator.next();
//For each row, iterate through all the columns
var cellIterator = row.cellIterator();
while (cellIterator.hasNext())
{
var cell = cellIterator.next();
//Check the cell type and format accordingly
switch (cell.getCellType())
{
case Cell.CELL_TYPE_NUMERIC:
logger.info("INT: "+cell.getNumericCellValue() );
break;
case Cell.CELL_TYPE_STRING:
logger.info("STR: "+cell.getStringCellValue() );
break;
}
}
}
file.close();
}catch( e){
logger.error(e);
}
return doc;
};