JSP & Excel

Where can I find information/source code/examples of JSP working with Excel?
Thanks!

<%@page import="java.sql.*,java.util.*"%>
Here is a sample code of Connectivity of JSP and Excel.
<%
Connection con = null;
DatabaseMetaData dbmetadata = null;
ResultSetMetaData rsmetadata = null;
ResultSet rsResponse = null;
String catalog = null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:test", "", "" );
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("Select * from [Sheet1$]");
if(rs != null){
while(rs.next()){
out.println(rs.getString(2));
}catch(Exception e){
out.println("Exception occured while opening the connection.");
out.println(e.getMessage());
}

Similar Messages

  • Running JSP Excel report from Forms 10g

    Perhaps this had been discussed before, though I didn't find an exact solution.
    We have a JSP report that displays data in MS Excel. Works fine if called from the url.
    The report shall be called from the form passing a parameter list with PARAMFORM=NO.
    Problem: reports runs as designed but opens up an empty Excel spreadsheet. No errors, no data..
    We are using RUN_REPORT_OBJECT with desformat=spreadsheet and paramform=no.
    We can't use just web.show_document alone since quite a few parameters need to be passed.
    I've read in one of the posts that a paper layout need to be created (in addition to web layout) to run RUN_REPORT_OBJECT. We've done that, but now it does not open EXCEL, and displays paper layout in a browser.
    So, how to call JSP (Excel) report from Forms passing parameter list without displaying the parameter form?
    Thank you

    What is the complete Application Server version you are using? Be sure you are using 10.1.2.2
    What platform and version is it installed?
    What version of Excel is installed on the client?
    Does it work if you use an RDF report?
    Try this:
    o Change DESFORMAT to DELIMITED
    o Append the following to the end of the URL created in the WEB.SHOW call:
    &mimetype=application/vnd.ms-excel
    The result should be the same as using SPREADSHEET.

  • Need help in jsp excel integration

    hello all
    plz help me in creating a excel file using jsp and writing data on to it .
    i also want to implement multi record additions ie create 2 rows of text fields and if i save the data it should be saved each in different rows(2 rows)

    Hi Katherine,
    you should update your version to Faces 1.0 Final and download the nightly build of struts-faces. It has been updated recently to work with the Final.

  • Jsp-excel problem

    iam generating reports in excel based on date submited through jsp file.here iam using poi-hssf .iam creating one woorkbook.xls and writing in to that file.my problem is if any user opened the woorkbook.xls then other user cant write and open xls file.
    can any body give solution how to approach this problem.
    if any new idea is thier where multiple client can write and read xls file

    iam generating reports in excel based on date submited through jsp file.here iam using poi-hssf .iam creating one woorkbook.xls and writing in to that file.my problem is if any user opened the woorkbook.xls then other user cant write and open xls file.
    can any body give solution how to approach this problem.
    if any new idea is thier where multiple client can write and read xls file

  • Jsp excel dde

    Hello Everyone,
    Im trying to set up jsp pages which can directly communicate with excel through DDE. In essence here is what i want to do: My jsp page contains tabular data, this data is refreshed through scripts every 5 secs, i now want a facility wherein if a user copy / pastes the table from html to excel spreadsheet then the data that is transferred to the excel should start updating itself after every 5 secs automatically.
    Any help, with links/references/codes will be very helpful.
    Thanks in advance
    HDJ

    Do NOT copy/paste into excel. Once you copy/paste, you lost link to web page.
    The trick is really inside Excel. Inside excel, click on Data --> Get External Data --> New Web Query
    and run your jsp web page as a web query. This way you can control the data refresh
    inside the excel.
    Hope this helps.

  • Java variables calculation on change in JSP (Excel replica)

    I have a excel sheet that I need to replicate in JSP (using struts 1 framework). Now everything is done but I am stuck at the calculation part. As you might have seen in excel, some columns are calculations based on other columns.
    So if I change field 'a', 'd' field should change automatically based on its formula (let's say, d=a*1.1 +b*2.1).
    Now I tried to use the funstion in javascript where I read 'a' and 'b' values from JSP, then I calculate and everything works fine. But when I try to assign the calculation result for field 'd' in JSP throush javascript, 'd' does not change.
    function adjustCalcs ()
    var a = eval("document.form.al.value");
    var b = eval("document.form.b.value");
    var dCalc = ((a * 1.05) + (b * 1.1));
    document.form.d.value = dCalc ; (this is where it should change the value of field 'd' in JSP, but ti won't...donno why?)
    Or is there any better way to do these dynamic changes in JSP ? Would appreciate the insight.
    Thanks,

    Fine. What's your problem in JSP side then? Do you want to let Java take over the calculation and "dynamic stuff" ? Then you need to let Javascript submit the form to the server side during the change event so that JSP can then display the result using taglibs/EL. But this is less good for user experience as this costs effectively one HTTP request and the user would see a "flash of content". Alternatively you can use Ajax for this to do it all asynchronously.

  • Date can not display correctly in excel from .jsp

    Hi,
    I create a .jsp report to export the data to excel. the report run OK, except the date field can not display correctly.
    for example in database :start date ='01-oct-2003'
    in the except it displays to 02/06/02.
    It seem all the date field can not be control in the report, and control by somthing else
    Doese anyone come accross this problem?
    Thanks

    Hi Rong,
    Are you using the following demonstration to build your JSP?
    http://otn.oracle.com/products/reports/htdocs/getstart/demonstrations/index.html
    (Output to Excel with Oracle9i Report)
    I tried to do the same, and inserted a database date field in the JSP using Reports. I found the following:
    While making the template inside Excel, if I make sure that the format of the date cells is "Date" - some particular date format, the date field values from Reports does not get exported correctly.
    However, if you make sure that inside the template, the format of the date cells is not date, but "General", then the date field values are correctly exported to Excel.
    Pl try it and let us know.
    Navneet.

  • OPEN JSP IN 2007 Excel

    I am trying to open JSP file in excel and I get the following message: excel cannot open the file because the file format or file extension is not valid.Verify that the file has not been corrupted and that the file extension matches the format of the file. By the way, I have MS excel 2007.
    here's my method:
    response.setContentType("application/vnd.ms-excel");
    response.setHeader("content-disposition","attachment; filename=Report.xlsx");
    Also, I have add the following to web.xml:
    <mime-mapping>
    <extension>xlsx</extension>
    <mime-type>application/vnd.ms-excel</mime-type>
    </mime-mapping>
    Could u pls resolve the issue asap.
    smruti

    SMRUTIMOHANTY wrote:
    Yes, i m generating a report in jspYou're generating a report with JSP? Rather use a Servlet for that.
    but i am not able to publish that report to excel page with extension .xlxs.
    With .xls i m publish the this report sucessfully.
    while opn report with extension .xls , i m getting warning mesg.
    pls help me out.First of all: are you actually generating an Excel report using some Excel API (JExcelAPI or Apache POI HSSF), or are you just sending some HTML to the client and fooling the client that it is an Excel file by changing the response headers?

  • Problem making an Excel file from a jsp

    Hi.
    I'm developing a web application that uses Excel for printing the reports. So far everything has worked fine, at least for the created Excel files that do not have any images on them. Now I need to create an excel file with an image as the header. I tried adding the necessary code to include the image, but when I open it, the image is not displayed (like when you open an HTML page that could load a certain image). I tried using different ways to set the src to see if maybe the path was the problem, but everytime I got the same result...
    How can I do this? How can I include the image and actually display it when the user opens the file in Excel?
    Thanks in advance
    CyberSpider

    I had a similar porblem....
    I got some help from...http://www.javaworld.com/javaworld/jw-10-2006/jw-1019-xmlexcel.html?page=1...
    This is my code in servlet...
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet spreadSheet = wb.createSheet("Users");
    spreadSheet.setColumnWidth((short) 0, (short) (256 * 25));
    spreadSheet.setColumnWidth((short) 1, (short) (256 * 25));
    // Creating Rows
    HSSFRow row = spreadSheet.createRow(0);
    HSSFCell cell = row.createCell((short) 1);
    cell.setCellValue("Year 2005");
    cell = row.createCell((short) 2);
    cell.setCellValue("Year 2004");
    HSSFRow row1 = spreadSheet.createRow(1);
    HSSFCellStyle cellStyle = wb.createCellStyle();
    cellStyle.setBorderRight(HSSFCellStyle.BORDER_MEDIUM);
    cellStyle.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
    cellStyle.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM);
    cellStyle.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);
    cell = row1.createCell((short) 0);
    cell.setCellValue("Revenue ($)");
    cell = row1.createCell((short) 1);
    cell.setCellValue("25656");
    cell = row1.createCell((short) 2);
    cell.setCellValue("15457");
    FileOutputStream output = new FileOutputStream(new File("/tmp/Users.xls"));
    response.setContentType("application/vnd.ms-excel");
    response.setHeader("Content-Disposition", "attachment;filename=Users.xls");
    ServletOutputStream out = response.getOutputStream();
    wb.write(output);
    output.flush();
    output.close();
    forward = null;
    In firefox i get the download dialog box but not able to open in from there,i need to save it and then open. In IE i dont get the dialog box instead the excell open inside the browser......Please help me to open a excel sheet onclick on a link "Export to excel" in jsp......
    Thanks in advance...

  • How to disable Format Warning when displaying JSP in Excel under MS-Office

    We have an application running in WebSphere 6.0 container, the application displays jsp data in Excel, it had no problem before MS-Office 2007 was install. However, after MS-Office 2007 is used, following format warning dialog box is always displayed:
    The file you are trying to open, ’Requests[1].xls’, is in a different format than specified by the file extension.
    Verify that the file is not corrupted and is from a trusted source before opening the file.
    The user has to click the "Yes" button before the Excel report can be successfully displayed. This is not acceptable by our production users, and I need your helps to get rid of this dialog box.
    The application uses struts. The Action class retrieves data from database and the data is forward to the result jsp
    in an data object set in an attribute of the session's Request object. The Action class also set the display info, such as the contentType,etc., in session's Response object (please see below for details).
    The result jsp retrieves data from the data object and display in Excel according to the display info provided in the
    session response object.
    To eliminate any possible problem that may be caused by the data, I have simplified the result jsp by removing original
    codes (such as data object forwarded from Action, and Tag Library, etc.), and just hardcoded few data for displaying in Excel, however, the same format warning box still always shows up.
    My Action class set display info as below:
    response.setContentType("application/vnd.ms-excel");
    response.setHeader("Expires", "0");
    response.setHeader("Cache-Control","must-revalidate, post-check=0, pre-check=0");
    response.setHeader("Pragma", "public");
    response.setHeader("content-disposition","attachment; filename=Requests.xls");
    My simplified result jsp is listed below:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <HTML>
    <HEAD>
    <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
    <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
    <!-- <%@ taglib prefix='c' uri='http://java.sun.com/jstl/core_rt'%> -->
    <TITLE></TITLE>
    </HEAD>
    <BODY>
    <TABLE border="1">
         <TBODY>
         <TR>
         <td><p align='left'>myData1</p></td>
         <td><p align='left'>myData2</p></td>
         <td><p align='left'>myData3</p></td>
         <td><p align='left'>myData4</p></td>
         </TR>
         </TBODY>
    </TABLE>
    </BODY>
    </HTML>
    So, I reduced the result jsp to contain only few hardcoded data, but the format warning always shows up. Is it caused by inconsistency between the MS-Office 2007 browser and the JSP engine in WebSphere 6.0 Web container? Need your help to resolve this problem.
    Thanks in advance.

    That's the caveat of fooling your webbrowser and Excel with a plain HTML page along an Excel content-type and Excel extension.
    Don't do that. That's plain stupid. Provide a real binary Excel file. You can create one using Apache POI HSSF or Andy Khan's JExcelAPI. Alternatively -and more recommended in case of large reports-, just use the CSV format. It's easy to create a CSV file in 20 lines of code and Excel perfectly understands CSV formats. Don't forget to change content-type to CSV.

  • Problem: JSP does not restore after downloading Excel.

    I have a "search.jsp" with a commandButton to generate excel. "Report.jsp" opens up in a new window when i click on this button by running below mentioned javascript. I can download Excel successfully by clicking on Download Excel link in report,jsp. Problem is, once i close this new window, I am unable to perform any other action in "search.jsp" even if i do not perform download. If i click on any other button or link "search.jsp", it replaces whole jsp with the Downlaod Excel link. and nothing happens after that . i need to close the seesion and start all over again from login page. Does anyone has solution. It will be big help. Thanks.
    JAVASCRIPT:
    function aaaa()
         mywindow =window.open('report.jsf', 'popupWindow', 'width=400,height=200,left=0,top=100,screenX=0,screenY=100');
    Following is report.jsp:
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
    <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
    <%@ taglib uri="http://www.backbase.com/2007/jsf" prefix="bjsf" %>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
    <f:view>
    <h:form>          
    <h:commandLink actionListener="#{searchpage.export}" value="Download Excel" />
    cancel
    </h:form>               
    </f:view>
    </body>
    </html>
    Following is export function which runs when i click on above commandlink "Download Excel":
         public void export(ActionEvent event) {
              try {
                   FacesContext context = FacesContext.getCurrentInstance();
                   HttpServletResponse response = (HttpServletResponse) context
                             .getExternalContext().getResponse();
                   response.setContentType("application/vnd.ms-excel");
                   response.setHeader("Content-Disposition",
                             "attachment; filename=report.xls");
                   ServletOutputStream servletOutputStream = response
                             .getOutputStream();
                   WritableWorkbook workbook = Workbook
                             .createWorkbook(servletOutputStream);
                   WritableSheet sheet = workbook.createSheet("First Sheet", 0);
                   WritableFont lfont = new WritableFont(WritableFont.ARIAL, 10);
                   lfont.setBoldStyle(WritableFont.BOLD);
                   WritableCellFormat lformat = new WritableCellFormat(lfont);
                   lformat.setBackground(Colour.DARK_RED2);
                   lformat.setBorder(Border.ALL, BorderLineStyle.THICK);
                   WritableFont rfont = new WritableFont(WritableFont.ARIAL, 10);
                   WritableCellFormat rformat = new WritableCellFormat(rfont);
                   rformat.setBorder(Border.ALL, BorderLineStyle.THIN);
                   for (int i = 0; i < this.list.size(); i++) {
                        HashMap h = (HashMap) this.list.get(i);
                        if (i == 0) {
                             Set s = (Set) h.keySet();
                             Iterator itr = s.iterator();
                             int j = 1;
                             while (itr.hasNext()) {
                                  Label label2 = new Label(j, 1, itr.next().toString(),
                                            lformat);
                                  sheet.addCell(label2);
                                  j++;
                        Collection c = h.values();
                        Iterator itr = c.iterator();
                        int j = 1;
                        while (itr.hasNext()) {
                             Label label2 = new Label(j, (i + 2), itr.next().toString(),
                                       rformat);
                             sheet.addCell(label2);
                             j++;
                   workbook.write();
                   workbook.close();
                   context.responseComplete();
              } catch (Exception e) {
                   e.printStackTrace();
         }

    Try upgrading JSF. I recall a Javascript-specific bug like this in a specific webbrowser. You could try to test in different webbrowsers. The latest JSF 1.2 is currently 1.2_14 which came out just 3 weeks ago. You can get it at [http://javaserverfaces.dev.java.net].
    Oh, you certainly need to invoke `FacesContext#responseComplete()` afterwards. This is really not the problem.

  • Using JSP to run batch file - command launches excel but doesn't open file

    I have written a jsp on a server which runs a batch file. Every command line in the batch works fine except the following:
    CALL "C:\Program Files\Microsoft Office\Office\Excel.exe" C:\Temp\spreadsheet.xls
    I can see that a command prompt has been opened and an instance of Excel has been created, but it does not open the file.
    I tried running the batch file on its own. It worked fine. I tried putting the java code in the jsp into a java class, that worked okay too. I think it might be to do with the fact that the client is trying lauch the application through the web, but it's missing some information such as paths.
    I am totally running out of ideas.. please help

    I guess if I know JSP stands for Java Server Pages..
    I would most probably know it runs on servers.Yes, you might, but if you were assuming that the path you gave would always lead to an executable running on the client you'd have a problem. It's worth asking.
    I must admit it's probably not the best idea, but if
    you can give me some advice on that, that would be
    greatJSPs shouldn't have code in them that doesn't pertain to view. I'd wrap something like a system call or Runtime.exec in a Java Bean that you can test off-line without the JSP. Then have the JSP instantiate an instance, invoke its method, and display the value that's returned.
    You've read this, of course:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    Everyone who uses Runtime.exec should.
    %

  • How to export a table in excel (in JSP)???

    hi all,
    I am using AJAX functionality in jsp to export a table into Excel.But i don't want to use it as it gives a hyperlink whereas i want a button which should work similar to hypelink.
    I mean to say i want a saperate export button which should work similar to the hyperlink.
    if anybody has any idea abt it....plz reply it soon.......

    So what you want to do is redirect to a page when the user clicks the button?
    So just put the button in a form with the action attribute set to wherever the hyperlink points now.
    And in case the button is already a part of a form, then on the onClick() event of the button, change the action attribute of the form to this particular hyperlink target and then cause it to submit.
    That ok?
    Or do you want the Excel file you're generating to be sent to the browser causing it to popup a dialog asking the user to save or open? If so take a look here http://forum.java.sun.com/thread.jspa?threadID=5170452&messageID=9655276

  • How Can i do a excel graphic with jsp?

    have to create an excel graph in jsp taken there values of a database.
    thanks a lot,
    Federico.

    "is used to spawn Excel from a JSP page, from the output of a HTML table but i dont know how (or if you can) to manipulate Excel through java so that you can get a chart."
    Let me rephrase this hehe =P
    You create an HTML table from the data you pull from the database. You then use the setContentType
    <%
    response.setContentType("application/vnd.ms-excel");
    %>
    this is to tell the browser it should look for Excel on the client machine, to dispay the output.
    Again i hope this helps even a little =)

  • Read an excel file using JSP in MII 12.1

    Hi,
    I want to read an excel file using jsp page. I dont want to use the UDS or ODBC for connecting to excel.
    I am trying to use org.apache.poi to read the excel file in jsp page.
    While running, its showing a compilation error "package org.apache.poi.hssf.usermodel does not exist"
    I have the jar files for it, where do we need to upload it so that jsp page works.
    Thanks a lot
    Regards,
    Neha Maheshwari

    The user doesn't want to save the excel file in server.
    I want to upload file and save its contents in database.
    I have the code to read and save excel data in database but not able to get the location to deploy the jar file.
    In general, if we are creating a jsp page in MII workbench which is using some jar file.
    Whats the location to upload this jar file so that the jsp page works correctly?

Maybe you are looking for

  • Using CMAppUtil file size is smaller when converted

    I'm new to using technet forums so if my question is in the wrong place I apologize.  I've just started using SCCM for Mac deployments and have a question regarding the file size after conversions using CMAppUtil. I've used CMAppUtil on a couple of .

  • Change Cell Size/Merge Cells?

    I'm wondering if you can (or how you can) merge multiple cells, or change the size/length of a cell. Thanks in advance.

  • Embedded Fonts for Accordion Headers

    Does anyone know how to get embedded fonts to show up in the accordion header? i checked out the Adobe LiveDoc on customizing the accordion component and it says to use the setStyle method. The font I've embedded is Futura. Here's what I've tried usi

  • What method is the EW website using to do this? (and why?)

    I asked a similar question in another thread, but apparently when a staffer answers you it automatically marks his answer as "Correct" whether the author wants it marked as such or not (giving the impression that the discussion is over). So I will as

  • Photoshop CS6 Error - 16

    I am using trial version of adobe photoshop CS6. I installed the product it runned fine for a day but then it gave error - 16. I reinstalled the product and it runned fine. But after 2 days it again gave the error. This happens with Adobe Flash Profe