使用 Apache POI 从 excel 文件中获取图像及其位置 [英] Get an image and its position from excel file using Apache POI

查看:32
本文介绍了使用 Apache POI 从 excel 文件中获取图像及其位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用 Apache POI 从 xls 电子表格中提取图像信息?

Is it possible to extract an image's information from an xls spreadsheet using Apache POI?

在我的一个项目中,我需要从 .xls 文件中读取一些图像.我可以一起阅读所有图像,但如何获取图像位置(如列和行号或坐标)?否则我可以获得图像位置,但我无法知道有关找到的位置的特定图像的信息,例如图片名称或扩展名或其他信息.我如何才能获得图像和位置?

In one of my projects, I need to read some images from a .xls file. I can read all images together, but how can I get images position (like columns and rows number or coordinates)? Otherwise I can get images position but I can't know information, like picture name or extension or others, about a specific image at the positions found. How I can get images and positions too?

这里 阅读所有图片... 和这里 获取图像位置...

推荐答案

看看这里:

http://poi.apache.org/components/spreadsheet/quick-guide.html#Images

示例:

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

    }
}

在此之后,您可以使用扩展 Magick 的 ImageInfo 之类的工具来查找各种配置.您甚至可以将图像转换为不同的尺寸.

After this, you can use tools like ImageInfo which extends Magick to find out various configs. Yo can even convert images to different sizes.

看看这个类:

http://blog.jaimon.co.uk/simpleimageinfo/SimpleImageInfo.java.html

--希望这有帮助

这篇关于使用 Apache POI 从 excel 文件中获取图像及其位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆