2016-07-13 118 views
0

我在java/jsp中有一個web應用程序。在我們的應用程序中有多個選項卡,並且在其中一個選項卡中,我必須顯示Excel表格中的數據。我試圖通過使用另存爲網頁選項將Excel錶轉換爲data.html文件。但是,當我嘗試包括在標籤中的HTML文件,即時得到下面的錯誤消息在jsp頁面顯示Excel數據

This content cannot be displayed in a frame 

我也試圖通過Tomcat服務器在Eclipse中運行的HTML文件,但得到了上述消息。當我嘗試通過網絡瀏覽器打開它時,數據會正確顯示。

我需要幫助獲取顯示在jsp頁面中的excel數據。任何幫助,這是非常感謝。謝謝

+0

什麼是您的Web應用程序的URL,以及從Excel轉換而來的HTML文件的URL是什麼? –

+0

web應用程序的url爲「http:// localhost:8080/pm/login.jsp。我無法使用tomcat服務器運行html文件,當我在eclipse中的瀏覽器中打開文件時,出現的URL是file:/// D:/PMProject/workspace/PM/WebContent/Data.html – vr3w3c9

回答

0

Columns marked with read box willl be displayed i have attached image here

你可以通過從servlet的數據使用下面的代碼它的工作原理如下

FileInputStream file1 = new FileInputStream(new File("your_file_path")); 
      System.out.println(file1); 
      file.close();  
      //Create Workbook instance holding reference to .xlsx file 
      XSSFWorkbook workbook111 = new XSSFWorkbook(file1); 

      //Get first/desired sheet from the workbook 
      XSSFSheet sheet111 = workbook111.getSheetAt(0); 


      Object[][] bookData_read = new String[sheet111.getLastRowNum()+1][3]; 

      int row_count11 = 0; 

      Iterator<Row> rowIterator111 = sheet111.iterator(); 

      while (rowIterator111.hasNext()) 
      { 
       Row row111 = rowIterator111.next(); 
       if (row_count11 == 0) { 
        row_count11++; 
       continue; 

       } 

       if (row_count11 > sheet111.getLastRowNum()) 
        break; 



       Cell cell11 = row111.getCell(4); 
       String cellvalue1 = ""; 

       if (cell11 != null && ! "".equals(cell11.getStringCellValue()) ||cell11 != null && ! "".equals(cell11.getNumericCellValue())) { 

        switch (cell11.getCellType()) { 

         case Cell.CELL_TYPE_STRING: 
          //System.out.print(cell.getStringCellValue()); 
          cellvalue1 = cell11.getStringCellValue(); 
          break; 
         case Cell.CELL_TYPE_BOOLEAN: 
          //System.out.print(cell.getBooleanCellValue()); 
          cellvalue1 = "" + cell11.getBooleanCellValue(); 
          break; 
         case Cell.CELL_TYPE_NUMERIC: 
          //System.out.print(cell.getNumericCellValue()); 
          cellvalue1 = "" + cell11.getNumericCellValue(); 
          break; 

        }} 


        String module1 = cellvalue1; 
        //System.out.println("module"+module1); 
        //System.out.println(cellvalue); 
        bookData_read[row_count11][0] = cellvalue1; 


        if(row111.getCell(5)!=null) 
        { 
          Cell cell2 = row111.getCell(5); 
          cellvalue1 = ""; 
         if (cell2 != null && ! "".equals(cell2.getStringCellValue())) { 



        switch (cell2.getCellType()) { 
         case Cell.CELL_TYPE_STRING: 
          //System.out.print(cell.getStringCellValue()); 
          cellvalue1 = cell2.getStringCellValue(); 
          break; 
         case Cell.CELL_TYPE_BOOLEAN: 
          //System.out.print(cell.getBooleanCellValue()); 
          cellvalue1 = "" + cell2.getBooleanCellValue(); 
          break; 
         case Cell.CELL_TYPE_NUMERIC: 
          //System.out.print(cell.getNumericCellValue()); 
          cellvalue1 = "" + cell2.getNumericCellValue(); 
          break; 
        } }} 
        String submodule = cellvalue1; 
        //System.out.println("submodule"+submodule); 

        // System.out.println(cellvalue); 
        bookData_read[row_count11][1] = cellvalue1; 



        if(row111.getCell(5)!=null && ! "".equals(row111.getCell(5).getStringCellValue())) 
        { 
    //    if(row.getCell(7)!=null && ! "".equals(row.getCell(7).getStringCellValue())) 
    //    { 
    //      
        Cell cell3 = row111.getCell(8); 
        cellvalue1 = ""; 
        if (cell3 != null && ! "".equals(cell3.getStringCellValue())) { 
        switch (cell3.getCellType()) { 
         case Cell.CELL_TYPE_STRING: 

          cellvalue1 = cell3.getStringCellValue(); 
          break; 
         case Cell.CELL_TYPE_BOOLEAN: 

          cellvalue1 = "" + cell3.getBooleanCellValue(); 
          break; 
         case Cell.CELL_TYPE_NUMERIC: 

          cellvalue1 = "" + cell3.getNumericCellValue(); 
          break;}} 


        String temp = cellvalue1; 
        bookData_read[row_count11][2] = cellvalue1; 

        } 
        else{ 

         continue; 
        } 


        row_count11++; 



      } 
      workbook111.close(); 

    request.setAttribute("modulesList", bookData_read); 
RequestDispatcher rd = request.getRequestDispatcher("/All_Modules.jsp"); 
     rd.forward(request, response); 
精細 Modules.java(servlet頁面)和Modules.jsp頁面代碼是給在jsp

Modules.jsp頁面

<pre> <% 
    String[][] book_data = (String[][]) request.getAttribute("modulesList"); 
    System.out.println("book_data: " + book_data); 
    %> 
    <table class="table table-striped jambo_table bulk_action"> 
         <thead> 
          <tr class="headings"> 

          <th class="column-title"><center>Sr No. </center></th> 
          <th class="column-title"><center>Modules</center></th> 
          <th class="column-title"><center>Sub Modules </center></th> 
            <th class="column-title"><center>Test Case ID</center></th> 

        <th class="column-title"><center>Select All&nbsp;&nbsp;<input type="checkbox" class="chkSelectAll btn btn-primary" /></center></th> 
         <th class="column-title"><center>Screen Shot&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</center></th> 


         </thead> 
    <% 
    int counter11 = 1; 
    for (String[] device : book_data) { 
     if (device[0] != null && device[2] != null) { 
      System.out.println("device[0]: " + device[0]); 
    %> 
    <tr> 
     <td><center><%=counter11 %></center></td> 
     <td><center><%=device[0] %></center></td> 
     <td><center><%=device[1] %></center></td> 
     <td><center><%=device[2] %></center></td> 

     <td><center><input type="checkbox" id="check-all" class="flat" name="selectedmodules" value=<%=device[2]%>></center></td> 
     <td><center><input type="checkbox" id="check-all" class="flat" name="screenshots" value=<%=device[2]%>></center></td> 

    </tr> 

    <% 
    counter11++; 
     } 
    } 
    %> 
         </table> 
    </pre> 
+0

只是忽略

標籤刪除並在您的jsp中添加代碼 –