In Java, you can call Apache's poi operation EXCEL to insert an image into excel.
// Create a new workbook WB = new xssfworkbook (); // or new hssfworkbook (); // Add picture data to this workbook. // open the image inputstream is = new fileinputstream ("image1.jpeg"); byte [] bytes = ioutils. tobytearray (is); // Add the image to the workbook int pictureidx = WB. addpicture (bytes, workbook. picture_type_jpeg); is. close (); creationhelper helper = WB. getcreationhelper (); // create sheet = WB. createsheet (); // create the drawing patriarch. this is the top level container for all shapes. drawing drawing = sheet. createdrawingpatriarch (); // Add a picture shape clientanchor anchor = helper. createclientanchor (); // set top-left corner of the picture, // subsequent call of picture # resize () will operate relative to it // set the Image Location anchor. setcol1 (3); anchor. setrow1 (2); picture PICT = drawing. createpicture (anchor, pictureidx); // auto-size picture relative to its top-left corner Pict. resize (); // save workbook string file = "picture.xls"; if (WB instanceof xssfworkbook) file + = "X "; // output file fileoutputstream fileout = new fileoutputstream (File); WB. write (fileout); fileout. close ();
Link to this article: blog.csdn.net/joyous/article/details/8780112
Q group 236201801 Discussion