使用java读取excel数据

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(); 
        }
    }

}

  

猜你喜欢

转载自www.cnblogs.com/qinyios/p/11121629.html
今日推荐