Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet how to present the excel to the web browser in jsp
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


mike wang
how to present the excel to the web browser in jsp
4 Answer(s)      3 years and 6 months ago
Posted in : JSP-Servlet


How to present the content of the newly created excel file in the following jsp to the web browser:

<%@ page import="java.io.InputStream" %>
<%@ page import="org.apache.poi.xssf.usermodel.XSSFSheet"%>
<%@ page import="org.apache.poi.xssf.usermodel.XSSFWorkbook"%>
<%@ page contentType="application/vnd.ms-excel" %>
<%@ page import="java.io.*" %>
<%
        try {
           XSSFWorkbook wb = new XSSFWorkbook();
    XSSFSheet sheet1 = wb.createSheet("TA");
    XSSFSheet sheet2 = wb.createSheet("TM");
   XSSFSheet sheet3 = wb.createSheet("XFA");
    XSSFSheet sheet4 = wb.createSheet("OTHERS");

    FileOutputStream fileOut = new FileOutputStream
("c:\\excel\\test.xlsx");
    wb.write(fileOut);
    fileOut.close();    

        } catch ( Exception ex ) {

        } 
%> 
}

Advertisement
View Answers

May 19, 2011 at 11:46 AM


<%@page import="java.io.*"%>
<%@page import="java.util.*"%>
<%@page import="org.apache.poi.hssf.usermodel.HSSFSheet"%>
<%@page import="org.apache.poi.hssf.usermodel.HSSFWorkbook"%>
<%@page import="org.apache.poi.hssf.usermodel.HSSFRow"%>
<%@page import="org.apache.poi.hssf.usermodel.HSSFCell"%>
<table border="1">
<%
  short a=0;
  short b=1;
  short c=2;
  short d=3;
  int i=0;
    String   value1="", value2="",value3=" ", value4="";
    String filename ="C:/hello.xls"; 
    if(filename != null && !filename.equals("")){
    try{
    FileInputStream fs =new FileInputStream(filename);
    HSSFWorkbook wb = new HSSFWorkbook(fs);
    for(int k = 0; k < wb.getNumberOfSheets(); k++){
    int j=i+1;
    HSSFSheet sheet = wb.getSheetAt(k);
    int rows  = sheet.getPhysicalNumberOfRows();
    for(int r = 0; r < rows; r++){
    HSSFRow row   = sheet.getRow(r);
    int cells = row.getPhysicalNumberOfCells(); 
    out.write("<br>");
    HSSFCell cell1  = row.getCell(a);
      value1 = cell1.getStringCellValue();
    HSSFCell cell2  = row.getCell(b);
      value2 = cell2.getStringCellValue();
    HSSFCell cell3  = row.getCell(c);
      value3 = cell3.getStringCellValue();
    HSSFCell cell4  = row.getCell(d);
      value4 = cell4.getStringCellValue();
    %>
    <tr><td><%=value1%></td><td><%=value2%></td><td><%=value3%></td><td><%=value4%></td></tr>
    <%
    }
        i++;
    }
    }
    catch(Exception e){
    System.out.println(e);
    }
    }
    %>
    </table>


May 19, 2011 at 11:52 AM


Thanks for the answers, you are excellent! one more followup questions: May I add some user actions: such as update the cells then update the excel files. thanks so lot!

looking forward to your answers!



May 19, 2011 at 12:32 PM


does the solution to the original questions work for the excel with multiple sheets and complicated content:

for instance: the excel file looks like:

tree structure: value1----6 a1
a2 a3

sheet1 sheet2 sheet3 sheet4 button: update

after the user update the excell from the browser, how to allow the user to update the excel.



December 16, 2011 at 2:54 AM


Does anyone know how to add a browse upload functionally to this code? This code automatically does it and this is incorrect by my standards



Related Tutorials/Questions & Answers:
how to present the excel to the web browser in jsp
how to present the excel to the web browser in jsp  How to present the content of the newly created excel file in the following jsp to the web browser: <%@ page import="java.io.InputStream" %> <%@ page import
how to display the excel file in the web browser.
how to display the excel file in the web browser.  > %@ page.../vnd.ms-excel" > %> <%@ page import="java.io.*" %> <% >... FileOutputStream > ("c:\\excel\\aqtemplate.xlsx"); > wb.write
Advertisements
getting the excel path throuh web browser given from client(i.e thruogh .jsp)
getting the excel path throuh web browser given from client(i.e thruogh .jsp)  1)when client uploads the excel sheet through a .jsp page, 2)get that excel path from web browser and read the data from the excel and printing
How to export web page to excel using java or jsp or servlets
How to export web page to excel using java or jsp or servlets  Hi I am trying to export web page(jsp page ) to excel using jsp or servlets. I am... errors. Please can anyone tell me how to do this using java or jsp or servlets
Show pdf's in web browser by using jsp?
Show pdf's in web browser by using jsp?  Hi, I want to display pdf file in browser by clicking the link, available in JSP page. When am trying... status - 404. How can i resolve it in JSP
to run html code in web browser - JSP-Servlet
to run html code in web browser  how to run jsp file which calls html file on web browser??  Hi Friend, Try the following code: 1)form.jsp: Enter Name: 2)welcome.html: Add Profile Edit
how to display the excel file content in the jsp
how to display the excel file content in the jsp  How to present the content of the newly created excel file in the following jsp to the web browser...="application/vnd.ms-excel" %> <%@ page import="java.io.*" %> <
PHP Open Excel File in browser - PHP
PHP Open Excel File in browser  How we can open an excel file using PHP code. I don?t want to let the user to download it rather I would like to get it open in the web browser. Any help would be great. Thank you very much
How to export chart(graph) generated by jsp into a excel?
How to export chart(graph) generated by jsp into a excel?  How to export chart(graph) generated by jsp into a excel? I have a jsp page which generates charts . Now I need those charts to be exported into an excel.please help
how to create a jave version excel in jsp
how to create a jave version excel in jsp  I would like to create a java version excel in JSP. so the excel like document can be published in the internet. the user will be able to enter the information and click the save button
How to export data from jsp to excel sheet by using java
How to export data from jsp to excel sheet by using java   How to export data from jsp to excel sheet by using java
JSP TO EXCEL
JSP TO EXCEL  Hi sir/mam, How to import data to excel using jsp without retrieving database.   friend, you can't import excel data into the middle of an HTML pages (your JSP will result in an HTML page
How to disable browser back and forward button after logout [in struts2 or jsp]
How to disable browser back and forward button after logout [in struts2 or jsp]  How to disable browser back and forward button after logout [in struts2 or jsp] I am using window.history.forward(); function
how to create web page on jsp?
how to create web page on jsp?  how to create web page on jsp
How to Get The Data from Excel sheet into out jsp page???
How to Get The Data from Excel sheet into out jsp page???  How to Get The Data from excel sheet to out jsp page in webApp
How to browse excel file and stored the contents into the database using jsp/servlet?
How to browse excel file and stored the contents into the database using jsp/servlet?  Hi.. I want to browse excel file and stored the file data into the My-sql database using jsp/servlet
How to download web page table data, export the table records in an excel file and save
How to download web page table data, export the table records in an excel file and save  i have a web page(.jsp) which contains the table of 4 to 5 columns. i m displaying the table using in my jsp page. below this table i want
How to upload a large excel file - JSP-Servlet
How to upload a large excel file   Dear sir , How to upload a large excel file and how to read a that large excel file or how to get a each column values from that large excel file.For small file i am getting values
Java Web Browser Problem
Java Web Browser Problem  Hello When run my web browser this is not displaying complete page any of the website like other browser.So Plz help me...."); setTitle("NextVision Browser"); setSize(600,400); Container
How to disable browser back after logout - JSP-Servlet
How to disable browser back after logout  Dear All I created JSP.... Anyone having idea how to disable browser back button after logout, please... problem is, when i am clicking browser back button i can see my old visited pages
how to disable back button of a browser after logging in? - JSP-Servlet
how to disable back button of a browser after logging in?  how to disable back button of a browser after logging in?  where is the source code
JSP to Excel - JSP-Servlet
JSP to Excel  Need an example of JSP and Excel database connection. Thanks
jsp excel code - JSP-Servlet
jsp excel code  hi how to store html form data into excel sheet by using jsp? and repeat this process continuously for entire sheet
how to read values from excel sheet and compare with database using jsp
how to read values from excel sheet and compare with database using jsp  hi sir i am arun how to read values from excel sheet and compare with database using jsp coding i.e, if i have 6(assetid,assetname,serialno,cubical
Function data from web in MS excel
data from one webpage to Excel using function Data - From Web. The problem is that this web page has at the end .jsp . When I open it via Excel, click to data... believe that the reason is format of .jsp because another web pages are working
How to disable browser back after logout - JSP-Servlet
How to disable browser back after logout  thanks deepak, i tried but if i am clicking back still i can see my old pages. i copied your code in my logout page. please if you have any other solution, please give me
difference from browser to browser - JSP-Servlet
difference from browser to browser  I am developing a project in jsp. When browse in mozilla it works good and when I open it with IE there is a difference how to overcome this problem.Thanks in advance
jsp to excel - JSP-Servlet
jsp to excel  Hi All, I'm writing a program of jsp to Excel conversion with Using POI. My problem is i'm unable to put multiple data into excel...)); } FileOutputStream fileOut = new FileOutputStream("c:\\excel\\wct.xls
Excel - JSP-Servlet
Excel  How to export data from jsp to excel sheet. I am using struts1.2 in my application.  Hi friend, Code to data from Jsp to excel...: "success.jsp" For more information on excel sheet Using JSP visit
jsp data in excel - JSP-Servlet
jsp data in excel  i have create jsp page which has button for excel.this calls jsp which contains code which has and then code for present data... and this query data has come from beans and using beans i put it in excel jsp in table
how to disable browser back button
how to disable browser back button  Am doing a web application in that how to disable browser back button using java script
 

 

 

DMCA.com