// Poi sheet to take the sheet in Excel
Public class readexcelpicture {
Public readexcelpicture (){
}
Public map readpicture (string excelpath) throws invalidformatexception, ioexception {
Fileinputstream FCM = new fileinputstream (excelpath );
Hssfworkbook workbook = (hssfworkbook) workbookfactory. Create (FS );
List // The first partition table in the Excel worksheet obtained by false settings
Hssfsheet sheet = Workbook. getsheet ("0 ");
Map <integer, hssfpicturedata> map = new hashmap <integer, hssfpicturedata> ();
For (hssfshape shape: sheet. getdrawingpatriarch (). getchildren ()){
Hssfclientanchor anchor = (hssfclientanchor) shape. getanchor ();
Int rowindex = anchor. getrow1 ();
If (shape instanceof hssfpicture ){
Int rowmark = rowindex;
Picture = (hssfpicture) shape;
Int pictureindex = picture. getpictureindex ()-1;
Picturedata = pictures. Get (pictureindex );
Map. Put (rowmark, picturedata );
}
}
Return map;
}
Public static void main (string ARGs []) {
String excelpath = "D: \ Excel \ test.xls ";
String savepicturepath = "d :\\ images \\";
Readexcelpicture = new readexcelpicture ();
Map <integer, hssfpicturedata> map = readexcelpicture. readpicture (excelpath );
// Add a row index of the Excel worksheet you need. You must ensure that the index of the Excel worksheet contains a row index,
// In the Excel row index that has been obtained, the index I entered is 1.
Hssfpicturedata picturedata = map. Get (1 );
// Retrieve the file string that contains the slice format
String ext = picturedata. suggestfileextension ();
// The number of words that represent the information of a batch.
Byte [] DATA = picturedata. getdata ();
// The root segment is used to extract the segments to the magnetic field.
If (ext. Equals ("Jpeg ")){
Fileoutputstream out = new fileoutputstream (savepicturepath + "a.jpg ");
Out. Write (data );
Out. Close ();
}
If (ext. Equals ("PNG ")){
Fileoutputstream out = new fileoutputstream (savepicturepath + "a.png ");
Out. Write (data );
Out. Close ();
}
}
}