jxl:解析Excel资料
jxl:解析Excel文件
import java.io.File; import java.io.IOException; import jxl.Cell; import jxl.Sheet; import jxl.Workbook; import jxl.read.biff.BiffException; public class ExcelAnalizer { public static void showContent(File file) { try { Workbook rwb = Workbook.getWorkbook(file); Sheet[] sheets = rwb.getSheets(); if (sheets != null && sheets.length > 0) { for (int i = 0; i < sheets.length; i++) { System.err.println("---------------------------- " + sheets[i].getName() + " ------------------------------"); int rows = sheets[i].getRows(); for (int j = 0; j < rows; j++) { Cell[] cells = sheets[i].getRow(j); for (int k = 0; k < cells.length; k++) { String cellValue = cells[k].getContents(); System.out.print("\t" + cellValue); } System.out.println(""); } } } } catch (BiffException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } public static void main(String[] args) { String fileName = "d:/aa.xls"; File file = new File(fileName); ExcelAnalizer.showContent(file); } }