forked from hmkcode/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppRead.java
More file actions
59 lines (49 loc) · 1.81 KB
/
AppRead.java
File metadata and controls
59 lines (49 loc) · 1.81 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
package com.hmkcode.poi;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Date;
import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class AppRead
{
public static void main( String[] args )
{
Workbook wb = null;
try {
wb = WorkbookFactory.create(new File("workbook.xlsx"));
} catch (InvalidFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Sheet sheet = wb.getSheetAt(0);
//*********************************
Cell cell = sheet.getRow(0).getCell(0);
double numberVal = cell.getNumericCellValue();
System.out.println("Row: 0 - Column: 0 = "+numberVal);
//-----------------------------
cell = sheet.getRow(0).getCell(1);
String stringVal = cell.getStringCellValue();
System.out.println("Row: 0 - Column: 1 = "+stringVal);
//-----------------------------
cell = sheet.getRow(0).getCell(2);
Date dateVal = cell.getDateCellValue();
System.out.println("Row: 0 - Column: 2 = "+dateVal);
//-----------------------------
cell = sheet.getRow(0).getCell(3);
boolean booleanVal = cell.getBooleanCellValue();
System.out.println("Row: 0 - Column: 3 = "+booleanVal);
//-----------------------------
}
}