reading images and data from excel file using poi

做~自己de王妃 提交于 2020-01-06 08:17:36

问题


i know how to read data from excel xls/xlxs. now my requirement is that i have to read image and data from excel file using POI 3.8. can you please guide me how to do that. reading images and data both from one excel file using poi.... Thanks in advance


回答1:


Straight from the developer's guide:

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




回答2:


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();

    }
}


来源:https://stackoverflow.com/questions/13658315/reading-images-and-data-from-excel-file-using-poi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!