package excelOperation2; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; import jxl.Cell; import jxl.Sheet; import jxl.Workbook; public class testMain { public static void main(String[] args) { // TODO Auto-generated method stub try { File file = new File("myRes//a.xls"); // 創建文件對象 Workbook wb = Workbook.getWorkbook(file); // 從文件流中獲取Excel工作區對象(WorkBook) Sheet sheet = wb.getSheet(0); // 從工作區中取得頁(Sheet) for (int i = 0; i < sheet.getRows(); i++) { // 循環打印Excel表中的內容 for (int j = 0; j < sheet.getColumns(); j++) { Cell cell = sheet.getCell(j, i); System.out.printf(cell.getContents()+" "); } System.out.println(); } } catch (Exception e) { e.printStackTrace(); } } }
new FileOutputStream(filename,true)代表是追加寫入而不是覆蓋寫入