0

我知道如何从 excel xls/xlxs 读取数据。现在我的要求是我必须使用 POI 3.8 从 excel 文件中读取图像和数据。你能指导我怎么做吗?使用 poi 从一个 excel 文件中读取图像和数据....提前致谢

4

2 回答 2

3

直接来自开发者指南

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 :)

于 2012-12-01T10:32:51.827 回答
-1
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();

    }
}
于 2017-10-04T18:02:41.917 回答