Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
528 views
in Technique[技术] by (71.8m points)

java - Get an image and its position from excel file using Apache POI

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

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?

Here read all images... and here get images positions...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Have a look here:

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

Sample:

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

    }
}

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

Take a look at this class as well:

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

-- Hope this helps


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...