需要的jar包:jxl
public class ExcelUtils {
private static List list = new ArrayList();
private static MoviesListBean moviesListBean = new MoviesListBean();//根据具体的生成对应的对象文件
public static List getXlsData(String filePath) throws Exception {
// 创建输入流
InputStream stream = new FileInputStream(filePath);
// 获取Excel文件对象
Workbook rwb = Workbook.getWorkbook(stream);
// 获取文件的指定工作表 默认的第一个
Sheet sheet = rwb.getSheet(0);
// 行数(表头的目录不需要,从1开始)
for (int i = 1; i < sheet.getRows(); i++) {
// 创建一个数组 用来存储每一列的值
String[] str = new String[sheet.getColumns()];
Cell cell = null;
// 列数
for (int j = 0; j < sheet.getColumns(); j++) {
// 获取第i行,第j列的值
// cell = sheet.getCell(j, i);
String name = sheet.getCell(0, i).getContents();//名字
String director=sheet.getCell(2,i).getContents();//导演
String actor=sheet.getCell(3,i).getContents();//主演
String detail=sheet.getCell(4,i).getContents();//简介
String download_url=sheet.getCell(6,i).getContents();//下载地址
String file_path=sheet.getCell(6,i).getContents();//本地地址
String poster_url=sheet.getCell(7,i).getContents();//下载地址
String imagePath=sheet.getCell(7,i).getContents();//下载地址
moviesListBean.setName(name);
moviesListBean.setDirector(director);
moviesListBean.setDirector(director);
moviesListBean.setActor(actor);
moviesListBean.setDetail(detail);
moviesListBean.setDownload_url(download_url);
moviesListBean.setFile_path(file_path);
moviesListBean.setPoster_url(poster_url);
moviesListBean.setImagePath(imagePath);
}
// 把刚获取的列存入list,也可以存入到数据库
list.add(moviesListBean);
}
return list;
}