Poi sheet take the sheet in Excel

Source: Internet
Author: User

 

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.