2016-10-04 45 views
0

我有一個excel表單,其中包含多列數據以及包含文件路徑的列。當我將它上傳到extjs網格時,我想在提交到數據庫之前根據文件路徑列讀取blob數據。我沒有表單,點擊網格中的提交按鈕時需要獲取數據。我們如何從Excel工作表中讀取本地系統數據。我試圖讀取支持的映像(使用java spring),但它的讀取就像客戶端和服務器都在單個系統中一樣。我想從客戶端讀取blob。我怎樣才能在java中做到這一點。請提出一些建議。如何從excel表中讀取blob中的extjs

PFA

回答

0

私有靜態無效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(); 
    } 

}

+1

請解釋一下你的答案 – Mazz

+0

getDrawingPatriarch()將給HSSFPatriarch對象從我們可以列出所有圖像excel表格在getChildren()方法的幫助下。從那裏你可以得到像位置和字節,imagename,mimeType等圖像的細節 – sangamesh