10
10
*/
11
11
12
12
public class ExcelReader {
13
- public static final String SAMPLE_XLS_FILE_PATH = "./sample-xls-file.xls" ;
13
+ // public static final String SAMPLE_XLS_FILE_PATH = "./sample-xls-file.xls";
14
14
public static final String SAMPLE_XLSX_FILE_PATH = "./sample-xlsx-file.xlsx" ;
15
15
16
16
public static void main (String [] args ) throws IOException , InvalidFormatException {
@@ -21,32 +21,6 @@ public static void main(String[] args) throws IOException, InvalidFormatExceptio
21
21
// Retrieving the number of sheets in the Workbook
22
22
System .out .println ("Workbook has " + workbook .getNumberOfSheets () + " Sheets : " );
23
23
24
- /*
25
- =============================================================
26
- Iterating over all the sheets in the workbook (Multiple ways)
27
- =============================================================
28
- */
29
-
30
- // 1. You can obtain a sheetIterator and iterate over it
31
- Iterator <Sheet > sheetIterator = workbook .sheetIterator ();
32
- System .out .println ("Retrieving Sheets using Iterator" );
33
- while (sheetIterator .hasNext ()) {
34
- Sheet sheet = sheetIterator .next ();
35
- System .out .println ("=> " + sheet .getSheetName ());
36
- }
37
-
38
- // 2. Or you can use a for-each loop
39
- System .out .println ("Retrieving Sheets using for-each loop" );
40
- for (Sheet sheet : workbook ) {
41
- System .out .println ("=> " + sheet .getSheetName ());
42
- }
43
-
44
- // 3. Or you can use a Java 8 forEach wih lambda
45
- System .out .println ("Retrieving Sheets using Java 8 forEach with lambda" );
46
- workbook .forEach (sheet -> {
47
- System .out .println ("=> " + sheet .getSheetName ());
48
- });
49
-
50
24
/*
51
25
==================================================================
52
26
Iterating over all the rows and columns in a Sheet (Multiple ways)
@@ -62,6 +36,7 @@ Iterating over all the rows and columns in a Sheet (Multiple ways)
62
36
// 1. You can obtain a rowIterator and columnIterator and iterate over them
63
37
System .out .println ("\n \n Iterating over Rows and Columns using Iterator\n " );
64
38
Iterator <Row > rowIterator = sheet .rowIterator ();
39
+ StringBuilder sb = new StringBuilder ();
65
40
while (rowIterator .hasNext ()) {
66
41
Row row = rowIterator .next ();
67
42
@@ -71,29 +46,12 @@ Iterating over all the rows and columns in a Sheet (Multiple ways)
71
46
while (cellIterator .hasNext ()) {
72
47
Cell cell = cellIterator .next ();
73
48
String cellValue = dataFormatter .formatCellValue (cell );
74
- System .out .print (cellValue + "\t " );
75
- }
76
- System .out .println ();
77
- }
78
-
79
- // 2. Or you can use a for-each loop to iterate over the rows and columns
80
- System .out .println ("\n \n Iterating over Rows and Columns using for-each loop\n " );
81
- for (Row row : sheet ) {
82
- for (Cell cell : row ) {
83
- String cellValue = dataFormatter .formatCellValue (cell );
84
- System .out .print (cellValue + "\t " );
49
+ sb .append (cellValue );
85
50
}
86
- System .out .println ();
87
51
}
52
+ System .out .println (sb .toString ());
53
+ System .out .println (SQLParser .extractFieldsForTable (sb .toString (),"uf" ));
88
54
89
- // 3. Or you can use Java 8 forEach loop with lambda
90
- System .out .println ("\n \n Iterating over Rows and Columns using Java 8 forEach with lambda\n " );
91
- sheet .forEach (row -> {
92
- row .forEach (cell -> {
93
- printCellValue (cell );
94
- });
95
- System .out .println ();
96
- });
97
55
98
56
// Closing the workbook
99
57
workbook .close ();
0 commit comments