Export Query Data to Excel

Hey guys, I have a cfm page that I am using to query data, and the  result set is displayed on the same page when a user clicks submit.
My question is, I would like to create a clickable icon where, after a  user runs the query and the data table displays, I want the user to be  able to click a little Excel icon that will allow them to download the  data in Excel.
So, a user clicks on a little icon somewhere on the page and IE or  Firefox or whatever pops up a little dialog box asking them if they want  to OPEN or SAVE the file results.xls.  How can I do this?
Here is my current code, but where do I implement the cfoutput stuff to  export?  On the same page?
<cfquery name="qActivity" datasource="khamp" result="resultInfo">
     SELECT KHAMELEON.GL_DETAIL.ACCOUNT, KHAMELEON.GL_ACCOUNT.DES1, KHAMELEON.GL_DETAIL.ENTITY,
    SUM (KHAMELEON.GL_DETAIL.AMOUNT) AS "TotalAmt"           
     FROM KHAMELEON.GL_ACCOUNT, KHAMELEON.GL_DETAIL
    WHERE 0=0
    <cfif Form.Entity IS NOT "">
          AND KHAMELEON.GL_DETAIL.ENTITY = '#Form.Entity#'
     </cfif>
    AND KHAMELEON.GL_DETAIL.ACCTG_DATE <= '#Form.asofday#-#Form.asofmonth#-#Form.asofyear#'
    <cfif Form.accountnum IS NOT "">
    AND KHAMELEON.GL_ACCOUNT.ACCOUNT = '#Form.accountnum#'
    </cfif>
    AND KHAMELEON.GL_ACCOUNT.ACCOUNT=KHAMELEON.GL_DETAIL.ACCOUNT
    GROUP BY
KHAMELEON.GL_ACCOUNT.ACCOUNT,
KHAMELEON.GL_DETAIL.ACCOUNT,
KHAMELEON.GL_ACCOUNT.DES1,
KHAMELEON.GL_DETAIL.ENTITY
     HAVING SUM(KHAMELEON.GL_DETAIL.AMOUNT)<>0
     ORDER BY KHAMELEON.GL_ACCOUNT.ACCOUNT ASC
     </cfquery>
  <cfif resultInfo.Recordcount eq 0>
    No Records Match the Search Criteria.
    <cfelse>
    <hr/>
    <br/>
    <table border="1" class="displaytable">
<!--Headings Row-->  
        <tr>
           <th>Account</th>
           <th>Description</th>
           <th>Entity</th>
           <th>Book 1</th>
      </tr>
<!--Result Rows-->   
      <cfoutput query="qActivity">
      <tr>
        <td>#qActivity.ACCOUNT#</td>
        <td>#qActivity.DES1#</td>
        <td>#qActivity.ENTITY#</td>
        <td style="text-align:right">#NumberFormat('#qActivity.TotalAmt#', "_(999,999,999.99)")#</td>
      </tr>
      </cfoutput>
I got the following code off of a thread in the forum, but it trys to  download the excel file as soon as the query is run (the excel download  doesn't work though, it trys to download the actual cfm page instead):
<cfheader name="Content-Disposition"
value="inline; filename=tb.xls">
<cfcontent type="application/vnd.ms-excel">
<table border="2">
<tr>
<td> Account </td><td> Description </td><td> Entity </td><td> Book1 </td>
</tr>
<cfoutput query="qActivity">
<tr>
<td>#qActivity.ACCOUNT#</td><td>#qActivity.DES1#</td><td>#qActivity.ENTITY#</td><td>#NumberFormat('#qActivity.TotalAmt#', "_(999,999,999.99)")#</td>
</tr>
</cfoutput>
</table>
</cfcontent>
Thanks guysq

To actually get the data into excel, google "cold fusion excel poi" and look for Ben Nadel's cfc.  Otherwise you might have issues with Office 2007.
For the icon or whatever, make your query a session variable.  Then have the icon link to either a self closing popup or a very small iframe that exports the query to an excel file and then uses cfcontent to download it to the user.

Similar Messages

  • How can i export the data to excel which has 2 tables with same number of columns & column names?

    Hi everyone, again landed up with a problem.
    After trying a lot to do it myself, finally decided to post here..
    I have created a form in form builder 6i, in which on clicking a button the data gets exported to excel sheet.
    It is working fine with a single table. The problem now is that i am unable to do the same with 2 tables.
    Because both the tables have same number of columns & column names.
    Below are 2 tables with column names:
    Table-1 (MONTHLY_PART_1)
    Table-2 (MONTHLY_PART_2)
    SL_NO
    SL_NO
    COMP
    COMP
    DUE_DATE
    DUE_DATE
    U-1
    U-1
    U-2
    U-2
    U-4
    U-4
    U-20
    U-20
    U-25
    U-25
    Since both the tables have same column names, I'm getting the following error :
    Error 402 at line 103, column 4
      alias required in SELECT list of cursor to avoid duplicate column names.
    So How can i export the data to excel which has 2 tables with same number of columns & column names?
    Should i paste the code? Should i post this query in 'SQL and PL/SQL' Forum?
    Help me with this please.
    Thank You.

    You'll have to *alias* your columns, not prefix it with the table names:
    $[CHE_TEST@asterix1_impl] r
      1  declare
      2    cursor cData is
      3      with data as (
      4        select 1 id, 'test1' val1, 'a' val2 from dual
      5        union all
      6        select 1 id, '1test' val1, 'b' val2 from dual
      7        union all
      8        select 2 id, 'test2' val1, 'a' val2 from dual
      9        union all
    10        select 2 id, '2test' val1, 'b' val2 from dual
    11      )
    12      select a.id, b.id, a.val1, b.val1, a.val2, b.val2
    13      from data a, data b
    14      where a.id = b.id
    15      and a.val2 = 'a'
    16      and b.val2 = 'b';
    17  begin
    18    for rData in cData loop
    19      null;
    20    end loop;
    21* end;
      for rData in cData loop
    ERROR at line 18:
    ORA-06550: line 18, column 3:
    PLS-00402: alias required in SELECT list of cursor to avoid duplicate column names
    ORA-06550: line 18, column 3:
    PL/SQL: Statement ignored
    $[CHE_TEST@asterix1_impl] r
      1  declare
      2    cursor cData is
      3      with data as (
      4        select 1 id, 'test1' val1, 'a' val2 from dual
      5        union all
      6        select 1 id, '1test' val1, 'b' val2 from dual
      7        union all
      8        select 2 id, 'test2' val1, 'a' val2 from dual
      9        union all
    10        select 2 id, '2test' val1, 'b' val2 from dual
    11      )
    12      select a.id a_id, b.id b_id, a.val1 a_val1, b.val1 b_val1, a.val2 a_val2, b.val2 b_val2
    13      from data a, data b
    14      where a.id = b.id
    15      and a.val2 = 'a'
    16      and b.val2 = 'b';
    17  begin
    18    for rData in cData loop
    19      null;
    20    end loop;
    21* end;
    PL/SQL procedure successfully completed.
    cheers

  • Reg : Exporting BLOB data to EXCEL

    Hi ,
    I have a requirement of exporting BLOB data to EXCEL.
    I tried it but i ma facing issue.
    Can anyone suggest me how to do it.
    Thanks & Regards :
    Pramila Padam

    HI Timo ,
    You are the only one helping to our team.
    We are trying according to the link provided by you.
    We will do and tell you.
    Thanks & Regards :
    Pramila Padam

  • Exporting form data to excel help

    Hi there,
    I have created an interactive form using Livecycle Designer that comes with Adobe 9 Pro. Forms will be download from a website, completed and emailed back to me. I'm having trouble trying to export  the data to excel. Whilst it lets me export data to excel it does not appear in the logical order as it is on the form. I'm not sure how to fix this and/or if its possible to only have certain fields displayed in excel?
    Is it also possible to automate the process so that data in completed forms that i save will update the inforamtion in excel?
    Any help greatly appreciated, I'm new to forms.
    Windows XP
    Adobe Acrobat 9 Pro
    Microsoft Excel 2003
    Thanks,
    Ken

    You probably need to ask in the LiveCycle forum since this is a Designer issue I think. If you are doing the export from Acrobat, then list the steps you are using. However, the field order and such are going to be set by Designer.

  • Error when attempting to download SQ01 query data to Excel

    Hi Experts ,
    I am getting error when attempting to download SQ01 query data to Excel .
    Error message - Contact your system administrator. The following template is missing: sap_om.xls
    Message no. 0K 407
    I have looked through the SAP GUI installation files and can find no record of the missing file
    Help

    Hi
    Please check SAP note 305900 & 803067
    Regards
    Ravinder

  • What's the best way to export UTF8 data into Excel?

    Hi,
    Database charterer set is UTF8
         PARAMETER     VALUE
    1     NLS_NCHAR_CHARACTERSET UTF8
    2     NLS_CHARACTERSET     UTF8
    My requirement is that I want to export oracle data into excel file by using UTL_FILE oracle supplied package.
    But while writing data into excel files it’s looses in UTF8 encoding and writes some garbage data into file.
    I am very much sure that while retrieving the data form database it is perfectly encoded with UTF8, but after data is written to the file it eats the UTF encoding resulting into some garbage data.
    e.g.
    I am retrieving this filed from database which is UTF8 encoded in DB “Langäcker 55” but when it is written into excel it becomes “Langäcker 55”.
    Is Oracle UTL_FILE eating the UTF8 encoding while writing into file? if yes, is there utility which can help me to remain the UTF8 encoding as it is while writing in to excel file? Is there anythingi can do in Oracle to get this done?
    Thanks in advance.
    Thanks,
    Santosh

    Until now I have not found anyone who could write real Excel files (MS binary format) in PL/SQL. So I assume that you write your data in strings separated by a character like ; or |, aka CSV.
    Try to open your file with 'wb' (write binary) instead of 'w' and then use
    -- write data
    utl_file.put_raw(v_file,utl_raw.cast_to_raw(<your data>));
    --write remaining data
    utl_file.fflush(v_file);
    --close the file
    utl_file.fclose(v_file);Regards
    Marcus

  • How to export table data to excel in albpm

    Hi,
    we have an requirement to export table data to excel .
    we have to create an jsp in that jsp we have to have text fileds,we have to enter data to field after that we have to click on save once u click on save that data has to enter in below table and we should provide link to export that table data to excel.
    this is our totatl requirement.can u please suggest me how to do,i dont have any idea..
    Regards,
    Sharmila
    Edited by: user12171025 on Nov 5, 2009 8:44 PM

    Hi Daniel 
    Please have a look at below docs :-
    /people/subramanian.venkateswaran2/blog/2006/08/16/exporting-table-data-to-ms-excel-sheetenhanced-web-dynpro-binary-cache
    http://wiki.sdn.sap.com/wiki/display/WDJava/ExporttoExcel(WithoutthirdpartyAPIs)
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/d01854fd-1579-2c10-63ad-dd62edca2381?quicklink=index&overridelayout=true
    Regards
    Arun Jaiswal

  • How to export the data to excel in OAF Page - Urgent

    Hi All,
    I have a developed a page wich dispaly the records based on some condition.
    The Page has two regions.
    1.RowLayout Region
    2.Table Region
    Both the regions are getting the data from two diffrent VOs.
    In this case how to export the data to excel as the export button will not work if the page uses more than one VO(I think).
    Please help me.
    Thanks,
    Srinivas
    Edited by: SrinivasChanda on Oct 7, 2009 10:07 AM

    Hi Gaurav,
    Yes you are rite.When i tried exporting the data(which is coming from two different VOs altogether),i got only one region's data and then got error.
    Please note: Two regions(RowLayout,Table) are getting data from two different VOs
    below is one of the region(row layout) data:
    Hierarchy     Learning Certification Status     Learning Certification     Supervisor
    Direct Reports     Passed Only     All     Michael Swinnerton
    below is the error:               
    <div CLASS="errorText">               
    <html lang="en-US">               
    <head>               
    <script>               
    function ignoreWarnAboutChanges(url)               
    document.location.href = url;               
    </script>                
    <title>Error Page</title>               
    <link rel="stylesheet" charset="UTF-8" type="text/css" href="/OA_HTML/cabo/styles/blaf.css">               
    <META name="fwk-error" content="Error occured while processing the request">               
    <META name="fwk-error-detail" content="oracle.apps.fnd.framework.OAException: Application: FND     Message Name: FND_GENERIC_MESSAGE. Tokens: MESSAGE = java.io.IOException: Stream closed;           
    "     at oracle.apps.fnd.framework.OAException.wrapperException(OAException.java:891)"               
    "     at oracle.apps.fnd.framework.OAException.wrapperException(OAException.java:865)"               
    "     at OAErrorPage.jspService(OAErrorPage.jsp:34)"               
    "     at com.orionserver.http.OrionHttpJspPage.service(OrionHttpJspPage.java:56)"               
    "     at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:317)"               
    "     at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:465)"               
    "     at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:379)"               
    "     at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)"               
    "     at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:727)"               
    "     at com.evermind.server.http.ServletRequestDispatcher.include(ServletRequestDispatcher.java:119)"               
    "     at com.evermind.server.http.EvermindPageContext.handlePageThrowable(EvermindPageContext.java:547)"               
    "     at com.evermind.server.http.EvermindPageContext.handlePageException(EvermindPageContext.java:518)"               
    "     at OAExport.jspService(OAExport.jsp:122)"               
    "     at com.orionserver.http.OrionHttpJspPage.service(OrionHttpJspPage.java:56)"               
    "     at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:317)"               
    "     at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:465)"               
    "     at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:379)"               
    "     at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)"               
    "     at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:727)"               
    "     at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:306)"               
    "     at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:767)"               
    "     at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:259)"               
    "     at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:106)"               
    "     at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:803)"               
    "     at java.lang.Thread.run(Thread.java:534)"               
    ## Detail 0 ##               
    java.io.IOException: Stream closed               
    "     at java.io.BufferedWriter.ensureOpen(BufferedWriter.java:98)"               
    "     at java.io.BufferedWriter.write(BufferedWriter.java:197)"               
    "     at OAExport.jspService(OAExport.jsp:107)"               
    "     at com.orionserver.http.OrionHttpJspPage.service(OrionHttpJspPage.java:56)"               
    "     at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:317)"               
    "     at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:465)"               
    "     at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:379)"               
    "     at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)"               
    "     at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:727)"               
    "     at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:306)"               
    "     at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:767)"               
    "     at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:259)"               
    "     at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:106)"               
    "     at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:803)"               
    "     at java.lang.Thread.run(Thread.java:534)"               
    java.io.IOException: Stream closed               
    "     at java.io.BufferedWriter.ensureOpen(BufferedWriter.java:98)"               
    "     at java.io.BufferedWriter.write(BufferedWriter.java:197)"               
    "     at OAExport.jspService(OAExport.jsp:107)"               
    "     at com.orionserver.http.OrionHttpJspPage.service(OrionHttpJspPage.java:56)"               
    "     at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:317)"               
    "     at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:465)"               
    "     at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:379)"               
    "     at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)"               
    "     at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:727)"               
    "     at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:306)"               
    "     at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:767)"               
    "     at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:259)"               
    "     at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:106)"               
    "     at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:803)"               
    "     at java.lang.Thread.run(Thread.java:534)"               
    ">
    </head>
    <body>
    <table width=100%"" border=""0"" cellspacing=""0"" cellpadding=""0"">"               
    <tr> <td><img src="/OA_MEDIA/FNDSSCORP.gif" alt=""> </td></tr>               
    <tr> <td> </td>                
    <td> <a href= /OA_HTML/OALogout.jsp>Logout </a></td>                
    </tr>               
    <tr> <td width="100%" nowrap class="OraBGColorDark" >  </td> </tr>               
    </table>               
    <p>               
    <center>               
    <table width="95%" border="0" cellspacing="0" class="OraBGAccentDark" cellpadding="0">               
    <tr> <td>   </td> </tr>               
    <!-- <tr> <td class="OraErrorHeader"> <img src=/OA_HTML/cabo/images/errorl.gif> Error Page </td> </tr> -->               
    <tr> <td class="OraErrorHeader"> <center> Error Page </center> </td> </tr>               
    <tr> <td colspan=2 class="OraBGColorDark"> </td> </tr>               
    <tr> <td>   </td> </tr>                
    <tr> <td colspan=2 class="OraErrorText" >You have encountered an unexpected error. Please               
    contact the System Administrator for assistance. </td> </tr>                
    <tr> <td colspan=2 class="OraErrorText"> Click <a href=javascript:ignoreWarnAboutChanges("/OA_HTML/OAErrorDetailPage.jsp")> here </a> for exception details.                
    </td> </tr>               
    </table>               
    </center>               
    </div>               
    </body>               
    </html>
    Please help me to solve this issue.
    Thanks,
    Srinivas

  • Exporting table data to Excel

    Hello, i use af:exportCollectionActionListener component to export table data to Excel.
    there are 100 000 rows in my table. But only 65 535(may be is consilience that ushort = 0 to 65535) rows was exported.
    what are problems? Anybody know?
    Edited by: Beliansky Alexander on Sep 5, 2012 7:02 AM

    If i am not wrong thats a limit of excel. Not sure but.Google
    taken from "http://msdn.microsoft.com/en-us/library/office/ff700514.aspx"
    "Starting in Excel 2007, the "Big Grid" increases the maximum number of rows per worksheet from 65,536 to over 1 million, and the number of columns from 256 (IV) to 16,384 (XFD). "
    Edited by: in the line of fire on Sep 5, 2012 6:06 PM

  • Exporting table data to Excel sheet:

    Hi All
    My requirement is need to export table data to Excel sheet: for this
    I was done all, but I'm getting 500 Exception please contact u r system admin msg at run time, also Jxl/Workbook class not found msg but I downloaded Jxl.jar file and its showing in navigator>Lib>jxl.jar. There is no error signals in coding part.
    Thanks
    Polaka

    Hi,
    Copy your jxl.jar and open it with winzip. See if there is Workbook.class file inside it in the folder jxl.
    Try to download jxl.jar from this link
    http://www.java2s.com/Code/Jar/JKL/Downloadjxljar.htm
    and add.
    Best Wishes
    Idhaya R

  • How we export report data into excel in report 10g

    hi can any one tell me
    how we export report data into excel in report 10g (except spreadsheet)

    We can use TEXT_IO Package

  • Exporting SQL data to Excel 2010 files - Excel sets all columns to DT_WSTR, ignores numeric or currency

    It looks like this has been a problem since forever, but I'm hoping someone has a solution.  I'm exporting SQL data to an .xlsx file.  I have the columns in my query set to the appropriate values, e.g. SELECT Cast(column1 AS nvarchar()) 'column1',
    Cast(column2 as currency) 'column2'.  I have a spreadsheet and I've set the data type for each column.  I have an OLEDB connection manager with the connection string of
    Data Source=C:\MyFile.xlsx;Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties="Excel 12.0;";  When I look at the Advanced Editor of my OLE DB Destination Component, I see that all the Input Columns are of the correct datatype, but
    all the External Columns are of datatype DT_WSTR.  
    How can I get my numeric, currency, date fields to be written to Excel as numeric, currency, date?  Right now they all get written as text, any numbers get single quotes put in front of them so they are treated as text.  
    I'm using SSIS 2008 R2.
    I don't get it, SQL and Excel are both Microsoft, why is it so hard to get them to work together?!

    Hi,
    converting to DT_WSTR because you are converting this into nvarachar in your select statement in oledb source.
    are you looking into the oledb destination or Excel destination for data types.
    please remove the casting from your select and create the new table as showing in the following snapshot:
    http://zaimraza.wordpress.com/

  • Problems exporting query results to Excel

    Hi!
    I hope you can help me
    We have a web template that uses the class ZVIG_ART that we created in the transaction SE24, this class display some label in the query
    results, the problem is when we export this report to excel the label disappear. The numbers indicates the stock of the item and the label N/V indicates that the item is not in the  store's catalog. Another case is that we can have N/V items but with stock, for example the ITEM2 of the STORE3 with the label N/V-1piece.  How can we export this label to EXCEL?
               |  STORE1     |    STORE2   |  STORE3
    ITEM1      |  10 PIECES  |    N/V      |  20 PIECES
    ITEM2      |  11         |    20       | N/V-1PIECE
    Thanks in advanced.
    Veronica B.

    Hi Mari,
    Thanks for the reply.
    I can understand the resason for not being able to change the Posting Date. But what are the reasons for not being able to change the Document Date? What is the fiscal reason for not being able to change the Document Date? Please provide an example. Reversing the document doesn't work in this case as the SQ01 report would still include the incorrect date.
    Regards,
    Gary

  • Export of data to excel

    Hi All, Greetings. Help required for the below mentioned
    query.
    While exporting the display page data to excel, the format of
    data is lost when a '-' is encountered at the beginning of the text
    field. for ex " ------sample data-----------"
    The date and number fields present after the above mentioned
    text field that start with '-' are shown as string. so the excel
    format for date field and number field goes for a toss, if a '-' is
    present at the start of the text field. Kindly help me with a fix
    to stop the format loss
    Regards, Ram

    If you are exporting a substantial number of records to excel the best option id to use CSV format and then process the generated CSV file with excel.
    Exporting directly to excel format works well with small amounts of data, but with a large number of records system memory becomes an issue.
    If you feel the need to export directly into excel format you can try to increase the maximum memory allocated to SQLDeveloper by adding something like the following
    AddVMOption -Xmx1024Mto the sqldeveloper.conf file usually located in
    [SQLDEveloper_install_dir]\sqldeveloper\binadjust the number as you see fit, but bear in mind that there have been issues reported while meddling with this parameter.
    The default value for the parameter is stored in the ide.conf file usually located in
    [SQLDEveloper_install_dir]\ide\bin

  • Export query results to excel from forms

    Are there any ways to export query results to MS Excel format files from a form.
    Thanks.

    Here's my working code out of one of my forms that does this:
    PROCEDURE export_transactions_to_excel IS
    -- Declare the ole objects
    application ole2.obj_type;
    workbooks ole2.obj_type;
    workbook ole2.obj_type;
    worksheets ole2.obj_Type;
    worksheet ole2.obj_type;
    cell ole2.obj_type;
    -- my variables
    rowCounter Number := 1;
    local_cursor_Record number := :System.Cursor_Record;
    old_cursor_Style varchar2(100);
    errors_occurred boolean := false;
    Ole_Error Exception;
    pragma exception_init( Ole_Error, -305500 );
    my_alert_id ALERT;
    alert_response NUMBER;
    procedure place_value_in_cell( rownum_in in number
    , colnum_in in number
    , value_in in varchar2 )
    is
    -- Declare handles to OLE argument lists
    args ole2.list_Type;
    begin
    args := ole2.create_arglist;
    ole2.add_arg(args, rownum_in); /* row number */
    ole2.add_arg(args, colnum_in); /* column number */
    -- the next line is for excel97
    -- cell := ole2.invoke_obj( worksheet, 'Cells', args );
    cell := ole2.get_obj_property( worksheet, 'Cells', args );
    ole2.Destroy_arglist( args );
    ole2.set_property( cell, 'Value', value_in );
    ole2.release_obj (cell);
    end place_value_in_cell;
    procedure SaveSpreadsheet
    is
    args ole2.List_Type;
    vDateStamp varchar2(20);
    begin
    vDateStamp := to_char(sysdate,'mmddyyyy') &#0124; &#0124; '_' &#0124; &#0124; to_char(sysdate,'hh24miss');
    args := OLE2.CREATE_ARGLIST;
    OLE2.ADD_ARG(args, 'C:\PAPRETCC_' &#0124; &#0124; vDateStamp &#0124; &#0124; '.XLS');
    OLE2.INVOKE(worksheet, 'SaveAs', args);
    OLE2.DESTROY_ARGLIST(args);
    --args := Ole2.Create_ARgList;
    ole2.invoke( application, 'Quit' );
    end SaveSpreadSheet;
    procedure Open_EXCEL_Workbook is
    Begin
    application := ole2.create_obj('Excel.Application');
    --ole2.set_property( application, 'Visible', 'True' );
    -- Return object handle to the Workbooks collection
    workbooks := ole2.get_obj_property( application, 'Workbooks' ); -- invoke_obj w/ excel 97
    -- Add a new Workbook object to the Workbooks collection
    workbook := ole2.invoke_obj( workbooks, 'Add' );
    -- return object handle to the Worksheets collection for the
    -- Workbook
    worksheets := ole2.get_obj_property( workbook, 'Worksheets' ); -- invoke_obj w/ Excel97
    -- Add a new Worksheet to the Worksheets collection
    worksheet := ole2.invoke_obj( worksheets, 'Add');
    end open_EXCEL_workbook;
    PROCEDURE Write_Column_Headers IS
    BEGIN
    place_value_in_cell(rowCounter,1, 'Payer Name');
    place_Value_in_cell(rowCounter,2, 'Payer Address');
    place_value_in_cell(rowCounter,3, 'SSN');
    place_value_in_cell(rowCounter,4, 'Account');
    place_value_in_cell(rowCounter,5, 'Refund Receipt');
    place_value_in_cell(rowCounter,6, 'Pretax Allocation');
    place_value_in_cell(rowCounter,7, 'Tax Allocation');
    place_value_in_cell(rowCounter,8, 'Total Amount');
    place_value_in_cell(rowCounter,9, 'Orig Receipt');
    place_value_in_cell(rowCounter,10,'Orig Date');
    place_value_in_cell(rowCounter,11,'TR Number');
    place_value_in_Cell(rowCounter,12,'Date');
    place_Value_in_cell(rowCounter,13,'Status');
    place_value_in_cell(rowCounter,14,'Vt Number');
    rowCounter := rowCounter + 1;
    END Write_Column_Headers;
    PROCEDURE Export_The_Data IS
    original_receipt number;
    original_date DATE;
    original_transmittal_number number;
    BEGIN
    -- Return object handle to cell A1 on the Worksheet
    Go_block('Transactions');
    First_Record;
    LOOP
    IF alert_response = ALERT_BUTTON2 or
    (alert_response = ALERT_BUTTON1 and nvl(:transactions.rg_approval,'N') <> 'N' )
    -- :system.record_status = 'CHANGED')
    then
    place_value_in_cell( rowCounter, 1, :TRANSACTIONS.NDB_PAYEE_NAME );
    place_value_in_cell( rowCounter, 2, nvl(:TRANSACTIONS.NDB_PAYEE_ADDRESS,'unknown') );
    place_value_in_cell( rowCounter, 3, nvl(:TRANSACTIONS.NDB_SSN,'unknown') );
    place_value_in_cell( rowCounter, 4, :transactions.NDB_DESCRIPTION );
    place_value_in_cell( rowCounter, 5, to_char(:Transactions.transaction_group_EID) );
    place_Value_in_cell( rowCounter, 6, to_char(:transactions.ndb_pretax_amount) ); -- chg
    place_ value_in_Cell( rowCounter, 7, to_char(:transactions.ndb_tax_amount) );
    place_value_in_cell( rowCounter, 8, to_char(:transactions.amount_including_taxes) );
    original_receipt := revenue_pkg.original_receipt_number(
    :transactions.transaction_group_eid,
    :transactions.allocation_eid,
    :transactions.allocation_table );
    original_date := revenue_pkg.original_receipt_date(
    :transactions.transaction_group_eid,
    :transactions.allocation_eid,
    :transactions.allocation_table );
    original_transmittal_number := revenue_pkg.transmittal_number_for_receipt(original_receipt);
    place_value_in_cell( rowCounter, 9, nvl(to_char(original_receipt),'unknown') );
    place_value_in_cell( rowCounter, 10, nvl(to_char(original_date,'mm/dd/yyyy hh24:mi:ss'),'unknown') );
    place_value_in_cell( rowCounter, 11, nvl(to_char(original_transmittal_number),'unknown') );
    -- COMPTROLLER COLUMNS
    IF ( alert_response = ALERT_BUTTON1 and nvl(:transactions.rg_approval,'N') <> 'N' )
    THEN
    place_value_in_cell( rowCounter, 12, to_Char(sysdate,'mm/dd/yyyy') );
    place_value_in_cell( rowCounter, 13, nvl(:transactions.rg_approval,'N') );
    place_value_in_cell( rowCounter, 14, nvl(to_char(:location.vt_number),'NULL') );
    END IF;
    End If;
    exit when :SYSTEM.LAST_RECORD = 'TRUE';
    NEXT_RECORD;
    rowCounter := rowCounter + 1;
    END LOOP;
    END Export_The_Data;
    /* ----------------------------------- main procedure --------------------------------------*/
    BEGIN
    Begin
    my_alert_id := Find_Alert('THREE_BUTTON_ALERT');
    IF NOT ID_NULL( my_alert_id ) then
    alert_Response := SHOW_ALERT( my_alert_id );
    If (alert_response = ALERT_BUTTON1) OR
    (alert_response = ALERT_BUTTON2) then
    old_Cursor_style := get_application_property( CURSOR_STYLE );
    set_application_property( CURSOR_STYLE, 'BUSY' );
    Open_EXCEL_WorkBook;
    Write_Column_Headers;
    Export_The_Data;
    Else
    Raise Form_Trigger_Failure;
    End If;
    Else
    Raise Form_Trigger_Failure;
    End If;
    exception
    when Form_Trigger_Failure then
    RAISE;
    when Ole_Error then
    AlertSend( 'There was an error exporting the data to Microsoft Excel (receipt# ' &#0124; &#0124;
    to_Char(:transactions.transaction_Group_eid) &#0124; &#0124; ')', false );
    errors_occurred := TRUE;
    when others then
    AlertSend( SQLERRM, false );
    errors_occurred := TRUE;
    End;
    Ideally, I'd like to call SaveSpreadsheet in Export_The_Data, and just ExitExcel here,
    but it prompts for whether to save the changes and I don't know how to get around that
    right now. SO, we just save and exit, regardless.
    SaveSpreadSheet;
    -- Release the OLE objects
    ole2.release_obj (worksheet);
    ole2.release_obj (worksheets);
    ole2.release_obj (workbook);
    ole2.release_obj (workbooks);
    ole2.release_obj (application);
    IF NOT errors_occurred then -- stay on the record that caused the error
    Go_Record( local_cursor_Record );
    End If;
    Set_Application_Property ( CURSOR_STYLE, old_cursor_style );
    EXCEPTION
    When Form_Trigger_Failure then
    null;
    When Others then
    AlertSend( SQLERRM );
    END export_transactions_to_excel;

Maybe you are looking for