API介紹:
http://www.andykhan.com/jexcelapi/
API下載:
http://www.andykhan.com/jexcelapi/download.html
據我所知,無法支援Excel2007的檔案(xlsx檔),2003可以(xls檔)
jxl.read.biff.BiffException: Unable to recognize OLE stream為Excel版本問題
import jxl.*; import java.io.IOException; import java.io.File; import jxl.read.biff.BiffException; public class RExcel { public static void main(String[] args) { try { Workbook workbook = Workbook.getWorkbook(new File( "D:/Excel2003Test.xls")); // Excel檔案路徑 // Sheet sheet = workbook.getSheet("sheet1"); //指定要讀取哪個Sheet,輸入名稱(頁籤) Sheet sheet = workbook.getSheet(0); // 指定要讀取第幾個Sheet,輸入數字,起始是0(頁籤) for(int n=0;n0){ System.out.print(","); } System.out.print(sheet.getCell(m, n).getContents());// 取得Cell中的資料 //Sheet.getCell(column, row),A1為Sheet.getCell(0, 0) } System.out.println(); } System.out.println("總共有"+sheet.getColumns()+"行"); // 讀出文件有幾列 System.out.println("總共有"+sheet.getRows()+"列"); // 讀出文件有幾行 workbook.close(); // .關閉文件 } catch (BiffException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }
沒有留言:
張貼留言