|
| 1 | +package com.hmkcode.poi; |
| 2 | + |
| 3 | + |
| 4 | +import java.io.File; |
| 5 | +import java.io.FileNotFoundException; |
| 6 | +import java.io.FileOutputStream; |
| 7 | +import java.io.IOException; |
| 8 | +import java.util.Date; |
| 9 | + |
| 10 | +import org.apache.poi.hssf.util.CellReference; |
| 11 | +import org.apache.poi.openxml4j.exceptions.InvalidFormatException; |
| 12 | +import org.apache.poi.ss.usermodel.Cell; |
| 13 | +import org.apache.poi.ss.usermodel.CellStyle; |
| 14 | +import org.apache.poi.ss.usermodel.CreationHelper; |
| 15 | +import org.apache.poi.ss.usermodel.DateUtil; |
| 16 | +import org.apache.poi.ss.usermodel.Row; |
| 17 | +import org.apache.poi.ss.usermodel.Sheet; |
| 18 | +import org.apache.poi.ss.usermodel.Workbook; |
| 19 | +import org.apache.poi.ss.usermodel.WorkbookFactory; |
| 20 | +import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
| 21 | + |
| 22 | + |
| 23 | +public class AppRead |
| 24 | +{ |
| 25 | + public static void main( String[] args ) |
| 26 | + { |
| 27 | + Workbook wb = null; |
| 28 | + try { |
| 29 | + wb = WorkbookFactory.create(new File("workbook.xlsx")); |
| 30 | + } catch (InvalidFormatException e) { |
| 31 | + e.printStackTrace(); |
| 32 | + } catch (IOException e) { |
| 33 | + e.printStackTrace(); |
| 34 | + } |
| 35 | + |
| 36 | + Sheet sheet = wb.getSheetAt(0); |
| 37 | + |
| 38 | + //********************************* |
| 39 | + Cell cell = sheet.getRow(0).getCell(0); |
| 40 | + double numberVal = cell.getNumericCellValue(); |
| 41 | + System.out.println("Row: 0 - Column: 0 = "+numberVal); |
| 42 | + //----------------------------- |
| 43 | + cell = sheet.getRow(0).getCell(1); |
| 44 | + String stringVal = cell.getStringCellValue(); |
| 45 | + System.out.println("Row: 0 - Column: 1 = "+stringVal); |
| 46 | + //----------------------------- |
| 47 | + cell = sheet.getRow(0).getCell(2); |
| 48 | + Date dateVal = cell.getDateCellValue(); |
| 49 | + System.out.println("Row: 0 - Column: 2 = "+dateVal); |
| 50 | + //----------------------------- |
| 51 | + cell = sheet.getRow(0).getCell(3); |
| 52 | + boolean booleanVal = cell.getBooleanCellValue(); |
| 53 | + System.out.println("Row: 0 - Column: 3 = "+booleanVal); |
| 54 | + //----------------------------- |
| 55 | + |
| 56 | + } |
| 57 | + |
| 58 | + |
| 59 | +} |
0 commit comments