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



Home Answers Viewqa JSP-Servlet save excel file with save and open dilog box
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


kajal D bhujbal
save excel file with save and open dilog box
0 Answer(s)      2 years and 6 months ago
Posted in : JSP-Servlet


following is my jsp code it is working correct.. i want to save excel file throgh jsp bt not by hard coded path as i have written in my prog(File file=new File("c:\"+fname+".xls");) user should have freedom to save the file in any location so plz give me suggestions

<%@ page import="org.apache.poi.hssf.usermodel.HSSFSheet"%>
<%@ page import="org.apache.poi.hssf.usermodel.HSSFWorkbook"%>
<%@ page import="org.apache.poi.hssf.usermodel.HSSFCell"%>
<%@ page import="org.apache.poi.hssf.usermodel.HSSFRow"%>
<%@ page import="org.apache.poi.hssf.usermodel.HSSFCellStyle"%>
<%@ page import="org.apache.poi.hssf.util.HSSFColor"%>
<%@ page import="java.io.* " %>
<%@page import="java.sql.* "%>

<html>
<body bgcolor="lightgrey">
 <%
 String fname=request.getParameter("fname");
 if(fname.equals(""))
 {
     %><h1><b><i><% out.println("PLZ Enter  filename!");%></i></b></h1>
     <%
 }else
     {

        File file=new File("c:\\"+fname+".xls");
        session.setAttribute("fname",fname);
        boolean exists = file.exists();
        //boolean exists = file.exists();
        if (exists)
         {
            %>
            <h1><b><i>
            <%out.println("File or Directory exist.do u want to replace it? or PLZ enter another filename");%></i></b></h1>
            <h3><a href="replace.jsp">Replace the existing one</a></h3><br><br>
            <h3><a href="save2.jsp">Enter another filename</a></h3>
         <%

        }else
        {
            String s1=null;
            try
            {
                 String MyDate=(String)session.getAttribute( "MyDate" );
                 session.setAttribute( "MyDate", MyDate );

              HSSFWorkbook hwb=new HSSFWorkbook();
              HSSFSheet sheet =  hwb.createSheet("new sheet");
              HSSFSheet sheet1 =  hwb.createSheet("new sheet1");
              HSSFRow rowhead=   sheet.createRow((short)0);
              rowhead.createCell((short) 0).setCellValue("INSTRUMENT");
              rowhead.createCell((short) 1).setCellValue("SYMBOL");
              rowhead.createCell((short) 2).setCellValue("EXP_DATE");
              rowhead.createCell((short) 3).setCellValue("STR_PRICE");
              rowhead.createCell((short) 4).setCellValue("OPT_TYPE");
              rowhead.createCell((short) 5).setCellValue("OPEN_PRICE");
              rowhead.createCell((short) 6).setCellValue("HI_PRICE");
              rowhead.createCell((short) 7).setCellValue("LO_PRICE");
              rowhead.createCell((short) 8).setCellValue("CLOSE_PRICE");
             rowhead.createCell((short) 9).setCellValue("OPEN_INT*");
            rowhead.createCell((short) 10).setCellValue("TRD_QTY");
            rowhead.createCell((short) 11).setCellValue("NO_OF_CONT");
            rowhead.createCell((short) 12).setCellValue("NO_OF_TRADE");
            rowhead.createCell((short) 13).setCellValue("NATIONAL_VAL");
            rowhead.createCell((short) 14).setCellValue("PR_VAL");








            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            String url = "jdbc:sqlserver://";
            Connection con = DriverManager.getConnection(url,"**","*******"); 
            Statement st=con.createStatement();
            ResultSet rs=st.executeQuery("Select * from CO ");
            int i=1;
            while(rs.next())
            {
                 HSSFRow row=   sheet.createRow((short)i);
                 s1=rs.getString("EXP_DATE");
                 if(s1.equals((String)session.getAttribute("MyDate")))
                 {

                      row.createCell((short) 0).setCellValue(rs.getString("INSTRUMENT"));
                      row.createCell((short) 1).setCellValue(rs.getString("SYMBOL"));
                      row.createCell((short) 2).setCellValue(rs.getString("EXP_DATE"));
                      row.createCell((short) 3).setCellValue(rs.getString("STR_PRICE"));
                      row.createCell((short) 4).setCellValue(rs.getString("OPT_TYPE"));
                      row.createCell((short) 5).setCellValue(rs.getString("OPEN_PRICE"));
                      row.createCell((short) 6).setCellValue(rs.getString("HI_PRICE"));
                      row.createCell((short) 7).setCellValue(rs.getString("LO_PRICE"));
                      row.createCell((short) 8).setCellValue(rs.getString("CLOSE_PRICE"));
                     row.createCell((short) 9).setCellValue(rs.getString("OPEN_INT*"));
                     row.createCell((short) 10).setCellValue(rs.getString("TRD_QTY"));
                     row.createCell((short) 12).setCellValue(rs.getString("NO_OF_TRADE"));
                     row.createCell((short) 13).setCellValue(rs.getString("NATIONAL_VAL"));
                     row.createCell((short) 14).setCellValue(rs.getString("PR_VAL"));
                        i++;
                }
            }


            FileOutputStream fileOut =  new FileOutputStream(file);
             hwb.write(fileOut);
             fileOut.close();
          %><h1><b><i><% out.println("Your excel file has been generated!");%>

         </i></b></h1>;
            </form>
            </body>
            </html>

        <% 


        }catch ( Exception ex )
        {   
            System.out.println(ex);
        } 

    }
}


  %>

Advertisement
View Answers

Related Tutorials/Questions & Answers:
save excel file with save and open dilog box
save excel file with save and open dilog box  following is my jsp code it is working correct.. i want to save excel file throgh jsp bt not by hard...");) user should have freedom to save the file in any location so plz give me
save data in excel
save data in excel  hello sir, i'm new to this field i want to know can i save data in excel by html forms input,means if any one fill up form online then it is save offline in excel how can i do it can you give me solution sir
Advertisements
save data in excel
save data in excel  hello sir, i'm new to this field i want to know can i save data in excel by html forms input,means if any one fill up form online then it is save offline in excel how can i do it can you give me solution sir
upload and save the file
upload and save the file  upload and save a file from a computer to specific location of remote computer using jsp
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... be displayed and ask me to save the file. on clicking the save button the data should be exported in to the excel file. any views??? Thanks in advance
how to capture IE browser FileDownload box open ,save and cancel event - JSP-Servlet
how to capture IE browser FileDownload box open ,save and cancel event ... to capture open,save and cancel event of filedownload box in javascript. Please... on download button ,then we are writing file content in response object's output
Create and Save Excel File in JSP
Create and Save Excel File in JSP  ... and saving Excel file from JSP application. In this example we are going... file.  To create an excel sheet we can use third party API which is Apache
To save table format data in pdf/excel in jsp
To save table format data in pdf/excel in jsp  Hello, I am doing web... table. So my question is ,I want so save this html format data in pdf/excel format... can save html table data in pdf/excel format.Your inputs are valuable to me
Text field save as word file
Text field save as word file  Dear experts At run how to save set of text field contains text into single Word file. To save in our desktop computer. Solve my problem
How to add save as dialoguebox to export into excel instead of directly saving..
How to add save as dialoguebox to export into excel instead of directly saving... from database and generated excel file at particular directory of my system directly but as per my need i have to add save as dialogue box to give user
save text file - Java Beginners
save text file  hi i have just start programming in java.please guide me if i want to read a text file in java.then the text file is save in which directory
retaining save dialog box even after clicking save button - Java Beginners
when i open save dialog box and input a file name that is already present... get it back??(even if i cal save dialog box again it would open again from...retaining save dialog box even after clicking save button  I am
how to import excel sheet into mysql database and save it as a table in database
how to import excel sheet into mysql database and save it as a table in database  sir, i want to import an excel sheet into a MySQL database and after importing it i want to store the excel sheet as a table in database
why java file save as its class name
why java file save as its class name  hi,this is subbareddy vajrala.my doubt is why java files save as its class names
how to add save,discard,& cancel button in a message box - Struts
how to add save,discard,& cancel button in a message box  how to add save,discard,& cancel button in a message box
How to save JPanel as gif or jpeg file
How to save JPanel as gif or jpeg file  i draw polygons , rectangles, lines on jpanel using draw line method drawpolygon methods etc, now i want save the data of jpanel which is drawn by me(lines,polygons) as a gif or jpeg file
How to save data to excel with a 2.1 work sheet format without changing it?
and save it to excel file then read it again .. the problem is , when data is saved , the extension file is changed to excel file with text ( tab limited...How to save data to excel with a 2.1 work sheet format without changing
Save file on Client Machine - Development process
Save file on Client Machine  Hi my application is running on main... from his machine try to save the file it gets saved in the serve machine i want to save the file created by my application on the client machine how can i do
Which extension i use for save hibernate file.
Which extension i use for save hibernate file.   Please give me answer that which extension i use for save the hibernate file and how i run that file as well as complie that file.   hi friend, Naming convention
How to save excel sheet into mysql database using blob or clob
How to save excel sheet into mysql database using blob or clob  Hi All, I am new to java and i need to upload excel sheet to mysql, please suggest me the steps to do this, i am able to connect to the database, from there i don't
code save word file in 10g database - SQL
code save word file in 10g database  I am not having any idea to save...(false); File file = new File(fileName); fis = new FileInputStream(file); pstmt = conn.prepareStatement("insert into file( file, file_data
How to save JPanel as gif or jpeg file
How to save JPanel as gif or jpeg file  i draw polygons , rectangles, lines on jpanel using draw line method drawpolygon methods etc, now i want save the data of jpanel which is drawn by me(lines,polygons) as a gif or jpeg file
How to upload and save a file in a folder - Java Beginners
How to upload and save a file in a folder  Hi How to upload and save a file in a folder? for example Agreement.jsp File: So when user browses the file and enters the submit button the respective file should
How to download and save a file from Internet using Java?
How to download and save a file from Internet using Java?  How to download and save a file from Internet using Java
URL file Download and Save in the Local Directory
URL file Download and Save in the Local Directory       This Program file download  from  URL and save this Url File in the specified directory. This program specifies
How to create file and save it into user defined path using jsp/servlet?
How to create file and save it into user defined path using jsp/servlet?  Hi.. Onclick event I have created one file.When file will create it should asked where to save file(like browse option
how to save html form data into .csv file using only jsp.
how to save html form data into .csv file using only jsp.  Dear all... inserted into the excel file. 1)Create form.jsp <html> <body> <form... in excel file."); }catch ( Exception ex ){ } %>
How i upload file and save that record in database using JSP?
How i upload file and save that record in database using JSP?  Hi All, I m the beginner in JSP and I want to upload the file and store that file... this file). Now refer the Employee Profile but it not work in localhost. If anybody
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
image save to folder in java
image save to folder in java  Hi, I am working with java. In my application i want to give facility to user to add and change image. I use open dialog box to select image, it will work properly i.e on button click open dialog
How to save form data to a csv file using jquery or ajax
How to save form data to a csv file using jquery or ajax  Please let... this. i am able to read the csv file using this code if (window.XMLHttpRequest...=data.responseText; Now the problem is ,i should write form data to a csv file using ajax
 

 

 

DMCA.com