私有靜態無效GetShapePosition(HttpServletRequest的請求){
try {
InputStream inp = new FileInputStream("D:/SVN_PROJECTS/WorkDevServer/EnrollSample.xls");
Workbook wb = WorkbookFactory.create(inp);
HSSFSheet sheet = (HSSFSheet)wb.getSheetAt(0);
HashMap<String,byte[]> hashMap = new HashMap<String,byte[]>();
HSSFPatriarch dravingPatriarch = sheet.getDrawingPatriarch();
java.util.List<HSSFShape> shapes = dravingPatriarch.getChildren();
for (HSSFShape shape : shapes) {
if (shape instanceof HSSFPicture) {
HSSFPicture hssfPicture = (HSSFPicture)shape;
int picIndex = hssfPicture.getPictureIndex();
String filename = hssfPicture.getFileName();
HSSFPictureData hssfPictureData = hssfPicture.getPictureData();
byte[] b = hssfPictureData.getData();
String s= hssfPictureData.getMimeType();
HSSFClientAnchor hca = hssfPicture.getPreferredSize();
System.out.println(" row : -> "+(hca.getRow1())+" column : -> "+(hca.getCol1()));
hashMap.put(String.valueOf((hca.getRow1()))+String.valueOf((hca.getCol1())),b);
}
}
request.getSession().setAttribute("ImghashMap", hashMap);
} catch (Exception e) {
e.printStackTrace();
}
}
請解釋一下你的答案 – Mazz
getDrawingPatriarch()將給HSSFPatriarch對象從我們可以列出所有圖像excel表格在getChildren()方法的幫助下。從那裏你可以得到像位置和字節,imagename,mimeType等圖像的細節 – sangamesh