package com.java.myapp; import java.io.File; import jxl.Cell; import jxl.Sheet; import jxl.Workbook; public class MyClass { public static void main(String[] args) { try{ String fileName = "C:\\java\\myExcel.xls"; Workbook workbook = Workbook.getWorkbook(new File(fileName)); Sheet ws = workbook.getSheet(0); Cell cell; for (int i = 0; i < ws.getRows(); i++) { cell = ws.getCell(0, i); // CustomerID System.out.println("CustomerID = " + cell.getContents()); cell = ws.getCell(1, i); // Name System.out.println("Name = " + cell.getContents()); cell = ws.getCell(2, i); // Email System.out.println("CustomerID = " + cell.getContents()); cell = ws.getCell(3, i); // CountryCode System.out.println("CountryCode = " + cell.getContents()); cell = ws.getCell(4, i); // Budget System.out.println("Budget = " + cell.getContents()); cell = ws.getCell(5, i); // Used System.out.println("Used = " + cell.getContents()); System.out.println("========================="); } workbook.close(); } catch (Exception e) { e.printStackTrace(); } } }
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท