save excel file with save and open dilog box

Ads
 

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 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);
        } 

    }
}


  %>
View Answers

Ads









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
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
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
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
How to save file in vi editor?
:w to save the file Type :wq to save and quit Type :q! to quit without saving...How to save file in vi editor?  Hi, I am trying to find commands to save the file in the vi editor? Can anyone show me the example and explain me
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
ModuleNotFoundError: No module named 'komica-save-file'
ModuleNotFoundError: No module named 'komica-save-file'  Hi, My... named 'komica-save-file' How to remove the ModuleNotFoundError: No module named 'komica-save-file' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'komica-save-file'
ModuleNotFoundError: No module named 'komica-save-file'  Hi, My... named 'komica-save-file' How to remove the ModuleNotFoundError: No module named 'komica-save-file' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'odoo8-addon-save-translation-file'
ModuleNotFoundError: No module named 'odoo8-addon-save-translation-file' ...: ModuleNotFoundError: No module named 'odoo8-addon-save-translation-file' How to remove the ModuleNotFoundError: No module named 'odoo8-addon-save-translation-file'
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 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
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 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
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
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
ModuleNotFoundError: No module named 'odoo10-addon-account-bank-statement-import-save-file'
-import-save-file'  Hi, My Python program is throwing following error...-import-save-file' How to remove the ModuleNotFoundError: No module named 'odoo10-addon-account-bank-statement-import-save-file' error? Thanks
ModuleNotFoundError: No module named 'odoo10-addon-account-bank-statement-import-save-file'
-import-save-file'  Hi, My Python program is throwing following error...-import-save-file' How to remove the ModuleNotFoundError: No module named 'odoo10-addon-account-bank-statement-import-save-file' error? Thanks
ModuleNotFoundError: No module named 'odoo8-addon-account-bank-statement-import-save-file'
-save-file'  Hi, My Python program is throwing following error...-import-save-file' How to remove the ModuleNotFoundError: No module named 'odoo8-addon-account-bank-statement-import-save-file' error? Thanks  
ModuleNotFoundError: No module named 'odoo8-addon-account-bank-statement-import-save-file'
-save-file'  Hi, My Python program is throwing following error...-import-save-file' How to remove the ModuleNotFoundError: No module named 'odoo8-addon-account-bank-statement-import-save-file' error? Thanks  
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
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 run time created text-file on a disk using jsp/servlet?
How to save run time created text-file on a disk using jsp/servlet?  I have a JSP page with save button.In that I created the file(e.g a.txt) at run-time,when I click on the save button,it will ask where to save the file
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
how to save an input to jsp page in a text file?ave an input given b
how to save an input to jsp page in a text file?ave an input given b  how to save the input given by the user in jsp page to a text file
Hibernate save()
This tutorial explain how save() works in hibernate

Ads