使用Apache POI从excel文件获取图像及其位置 [英] Get an image and its position from excel file using Apache POI
问题描述
可以使用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/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();
}
}
此后,您可以使用工具像ImageInfo,它扩展了Magick,找出各种配置。哟甚至可以将图像转换成不同的大小。
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屋!