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 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









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
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. ADS_TO_REPLACE_1 To create an excel sheet we can use third party API
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
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
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
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
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 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
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
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 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
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
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
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
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 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 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 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
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
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 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 ){ } %>
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 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
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  
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 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
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
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
Hibernate save()
This tutorial explain how save() works in hibernate
save uiimage to photo library
save uiimage to photo library  How to saved the clicked picture on camera roll in iPhone. I always want to write the file into photo library.   Save UIImage to photo library Creating a camera application in iPhone need
ModuleNotFoundError: No module named 'save'
ModuleNotFoundError: No module named 'save'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'save' How to remove the ModuleNotFoundError: No module named 'save' error
download or save jsp page
download or save jsp page  hii.., this is my jsp page .. This page is theater ticket. i want to download this page. so i need to save this page or download.. that depend on user wish how to make this page save or download <
download or save jsp page
download or save jsp page  hii.., this is my jsp page .. This page is theater ticket. i want to download this page. so i need to save this page or download.. that depend on user wish how to make this page save or download <
Save Table - SQL
Save Table  Where Oracle Tables or Database is saved? How to see Oracle Tables ? What are the websites to learn step by step Oracle. Help Me
How to save value in JSP
How to save value in JSP  Employee Name Time-IN Time-OUT Date t1 9 7 2012-12-12 t2... 324 2012-12-12 save i want to save dis value jsp to action ...how
save data DAO
save data DAO  how to save data in db   package com.tcs.ignite.dao; import com.tcs.ignite.bean.User; import com.tcs.ignite.connection.Connectiondetails; import java.sql.ResultSet; import java.sql.SQLException; import
Information Save Alert
Information Save Alert  Hi, Sir I am creating a web page there user can edit their information. I want a javascript that can show an alert message when user edit the information and trying to close or go to another page without
Java save file to database
Java save file to database In this section, you will learn how to insert file... between MySql database and java file with the help of various types of APIs, interfaces and methods. Then we have created an instance of File class and specify
How to open excel sheet when excel file is placed in some folder in desktop
How to open excel sheet when excel file is placed in some folder in desktop  How to open an excel sheet using windows.open in IE... I am getting an error msg that the path is not correct.. But i have specified the correct path

Ads