Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read in an image and output into a spreadsheet 1

Status
Not open for further replies.

TGJ

Programmer
Jan 31, 2005
64
CA
Hi,

I am trying to read a jpeg file and output it into a spreadsheet file as the first line in the spreadsheet. Any suggestions on how to read an image and then print it into a file?

Thanks,
Terry
 
When you say 'spreadsheet' I'm *guessing* you mean Excel.

I had no idea Excel *could* display images. Can it really ?

>>>> Any suggestions on how to read an image and then print it into a file?

Bit confused by this .... an image is a file ...


To manipulate the Excel format using java, you should look into the POI project at Apache. There is, obviously, no core APIs to deal with Excel.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Yes you can have images in ms excel. And yes I am trying to insert an image (which itself is a file) into a spreadsheet file. Have not found much luck googling.
 
download Java excel API from the following web site:

Code:
//create a new excel
WritableWorkbook wwb = Workbook.createWorkbook(os);
WritableSheet ws = wwb.createSheet("Test Sheet 1",0);
File image = new File("f:\\2.png");
            WritableImage wimage = new WritableImage(0,1,2,2,image);//x=0,y=1,column=2,row=2
ws.addImage(wimage);
wwb.write();
wwb.close();

For more details, please refer to the java doc:

Chinese Java Faq Forum
 
By the way, if you are going to use POI. Here is a little help from me.

Code:
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet();
ByteArrayOutputStream byteArrayOut =
new ByteArrayOutputStream();

BufferedImage bufferImg =
ImageIO.read(new File("D:\\fruit.PNG"));
ImageIO.write(bufferImg,"PNG",byteArrayOut);

HSSFClientAnchor anchor =
  new HSSFClientAnchor
    (5,0,500,122,(short) 0,
    5,(short)10,15);  
HSSFPatriarch patri =
sheet.createDrawingPatriarch();
patri.createPicture(anchor ,
    wb.addPicture(byteArrayOut.toByteArray(),
    HSSFWorkbook.PICTURE_TYPE_PNG));
         
ByteArrayOutputStream
outStream = new ByteArrayOutputStream();
wb.write(outStream);

Chinese Java Faq Forum
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top