以下是我的导入excel工具类
public class StuExcelUtil {
public static List<Student> redexcel(File file) throws Exception{
List<Student> list=new ArrayList<Student>();
InputStream input=new FileInputStream(file);
Workbook wb = Workbook.getWorkbook(input);
Sheet sheet=wb.getSheet(0);
int row=sheet.getRows();
int colums=sheet.getColumns();
/* 如何写入带图片的excel?
int imgNum=sheet.getNumberOfImages();
if(imgNum>0){
for (int i = 0; i < imgNum; i++) {
Image image=sheet.getDrawing(i);
byte[] imageData = image.getImageData();
String fileName = image.getImageFile().getName().trim();
}
}
*/
for (int i = 1; i < row; i++) {
for (int j = 0; j < colums; j++) {
Student stu=new Student();
stu.setName(sheet.getCell(j++, i).getContents());
stu.setSex(Integer.parseInt(sheet.getCell(j++, i).getContents()));
stu.setAge(Integer.parseInt(sheet.getCell(j++, i).getContents()));
stu.setGrade(Integer.parseInt(sheet.getCell(j++, i).getContents()));
stu.setWishType(Integer.parseInt(sheet.getCell(j++, i).getContents()));
stu.setWishDesc(sheet.getCell(j++, i).getContents());
stu.setWishStory(sheet.getCell(j++, i).getContents());
stu.setTeacherWords(sheet.getCell(j++, i).getContents());
stu.setTeacherMobile(DesUtils.encryptBasedDes(sheet.getCell(j++,i).getContents()));
list.add(stu);
}
}
return list;
}
}