cellDataType 엑셀 파일 준비
public class Project03_C {
public static void main(String[] args) {
String fileName="cellDataType.xlsx";
try(FileInputStream fis=new FileInputStream(fileName)) {
XSSFWorkbook workbook=new XSSFWorkbook(fis);
XSSFSheet sheet=workbook.getSheetAt(0);
Iterator<Row>rows=sheet.rowIterator();
while(rows.hasNext()) {
XSSFRow row=(XSSFRow)rows.next();
Iterator<Cell>cells=row.cellIterator();
while(cells.hasNext()) {
XSSFCell cell=(XSSFCell)cells.next();
CellType type=cell.getCellTypeEnum();
if(type==CellType.STRING) {
System.out.println("["+cell.getRowIndex()+","
+cell.getColumnIndex()+"]=STRING; Value="
+cell.getRichStringCellValue().toString());
}else if(type==CellType.NUMERIC) {
System.out.println("["+cell.getRowIndex()+","
+cell.getColumnIndex()+"]=NUMERIC; Value="
+cell.getNumericCellValue());
}else if(type==CellType.BOOLEAN) {
System.out.println("["+cell.getRowIndex()+","
+cell.getColumnIndex()+"]=BOOLEAN; Value="
+cell.getBooleanCellValue());
}else if(type==CellType.BLANK) {
System.out.println("["+cell.getRowIndex()+","
+cell.getColumnIndex()+"]=BLANK CELL");
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
[0,0]=STRING; Value=x
[0,1]=NUMERIC; Value=2.0
[0,2]=STRING; Value=A
[0,3]=BOOLEAN; Value=false
[0,4]=STRING; Value=B
[1,0]=BOOLEAN; Value=true
[1,1]=NUMERIC; Value=1.0
[1,2]=STRING; Value=Y
[1,3]=STRING; Value=X
[1,4]=NUMERIC; Value=10.0
'자바TPC 프로젝트' 카테고리의 다른 글
P4. iText API를 이용한 PDF table 만들기(2) (0) | 2022.02.07 |
---|---|
P4. iText API를 이용한 PDF table 만들기(1) (0) | 2022.02.07 |
P3 Excel에 이미지 저장하기(2) (0) | 2022.02.06 |
P3 Excel파일 Reading하기 (1) ClassNotFoundException: org.apache.xmlbeans.XmlObject 에러해결 (0) | 2022.02.06 |
P2 Jsoup API를 이용하여 웹 페이지 Crawling 하기(2) (0) | 2022.02.04 |