【发布时间】:2012-12-01 09:59:26
【问题描述】:
我知道如何从 excel xls/xlxs 中读取数据。现在我的要求是我必须使用 POI 3.8 从 excel 文件中读取图像和数据。你能指导我怎么做吗? 使用 poi 从一个 excel 文件中读取图像和数据。在此先感谢
【问题讨论】:
标签: java apache-poi
我知道如何从 excel xls/xlxs 中读取数据。现在我的要求是我必须使用 POI 3.8 从 excel 文件中读取图像和数据。你能指导我怎么做吗? 使用 poi 从一个 excel 文件中读取图像和数据。在此先感谢
【问题讨论】:
标签: java apache-poi
List lst = workbook.getAllPictures();
for (Iterator it = lst.iterator(); it.hasNext(); ) {
PictureData pict = (PictureData)it.next();
String ext = pict.suggestFileExtension();
byte[] data = pict.getData();
if (ext.equals("jpeg")){
FileOutputStream out = new FileOutputStream("pict.jpg");
out.write(data);
out.close();
}
}
RTM :)
【讨论】:
XSSFSheet mySheet1 = workbook.getSheetAt(0);
Iterator<Row> rowIterator1 = mySheet1.iterator();
if(rowIterator1.hasNext())
{
rowIterator1.next();
}
int pcount=1;
Iterator<XSSFPictureData> it = lst.iterator();
for (int i=0; i<lst.size(); i++)
{
Row row = rowIterator1.next();
// PictureData pict = (PictureData)it.next();
PictureData pict = (PictureData)lst.get(i);
String ext = pict.suggestFileExtension();
byte[] data = pict.getData();
String studentName = row.getCell(3).getStringCellValue();
int age =(int)row.getCell(14).getNumericCellValue();
int year = (int)row.getCell(16).getNumericCellValue();
System.out.println(studentName+":"+age+":"+year);
FileOutputStream out = new FileOutputStream("D:\\excel\\RPC\\"+pcount+"."+year+"."+age+".png");
out.write(data);
out.close();
pcount++;
rowIterator1.hasNext();
}
}
【讨论】: