天天看点

jxl 读取excel

import java.io.File;

import java.io.FileInputStream;

import java.io.IOException;

import java.io.InputStream;

import java.util.ArrayList;

import java.util.List;

import jxl.Cell;

import jxl.Sheet;

import jxl.Workbook;

import jxl.read.biff.BiffException;

public class ReadExcel_to {

public static List<String[]> readExcel(File fielPath) throws BiffException, IOException{

List<String[]> list = new ArrayList<String[]>();

Workbook rwb = null;

Cell cell = null;

InputStream stream = new FileInputStream(fielPath);

rwb = Workbook.getWorkbook(stream);

Sheet sheet = rwb.getSheet(0);

for(int i=1; i<sheet.getRows(); i++){

String[] str = new String[sheet.getColumns()];

for(int j=0; j<sheet.getColumns(); j++){

cell = sheet.getCell(j,i);

str[j] = cell.getContents();

}

list.add(str);

}

return list;

}

}