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') | | '_' | | to_char(sysdate,'hh24miss');
args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(args, 'C:\PAPRETCC_' | | vDateStamp | | '.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;

Similar Messages

  • Http 404 error exporting query result into Excel.

    Hello. I'm getting an Http 404 The webpage cannot be found" error when trying to export any APEX application's query results into Excel (Application Express 3.2.1.00.10). This was working fine before. Nothing changed with our APEX application. I've been always using I.E. Version 7.0.5730.11 with no problems. I've reset the I.E. defaults and still the problem exists. I've downloaded Mozilla Firefox and the problem does not happen. However, I would like to know why my I.E. still gets this error? Any feedback or suggestions would greatly be appreciated. Thanks for your time.

    My EI settings are as follows:
    Tools -> Internet Options -> Security
    All Three: Internet, Local Intrarnet, and Trusted Sites ... at Custom Level have the following settings:
    Downloads:
    Automatic prompting for file downloads = Enable
    File download = Enable
    Font download = Enable
    Problem still exists.
    Thanks for the help.... any additional feedback or suggestions would greatly be appreciated. Thanks for your time.

  • 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

  • About exporting query result to excel

    Hi all,
    I take the report result to an excel file and at this point I am being asked for my user name and password of BW login, repeatedly for many times, based on the amount of data it contains. Its quite irritating, as i need to fill that each time, it asks for that. So kindly suggest me, how to deal with this.
    Regards,
    Naveen.A

    Hi Naveen,
    Not sure that understood what you exactly meant. But will try to help. When you execute query in BEx you can save a workbook detaching it from a server. In this case all reporting information will be kept without further updating from a server. The client will just open the wb and see all information. Certainly, he will not be able to make drilldowns. But for this you save your wb as a view with all drildowns already done.
    Best regards,
    Eugene

  • How to open the TFS query results in Excel?

    Hello Guys,
    Question 1: Is there any way to export the query results from the TFS web browser?
    Question 2: Is there any way to export the query results from Team Explorer 2013?
    Here is the query results in TFS:
    How do I export this result in excel for further analysis? 
    I have also connected to Team explorer 2013 and right clicked on the query, but there is no option to open the results in Excel, see below:

    Hello,
    _Pls follow these guide lines for ensuring proper output in Microsoft Excel:
    1.First compare the fields properties and the frames properties between the reports created with wizard and the reports created manually.
    2. Do not leave any space between two adjacent objects.
    Explanation: Because any space, including a few pixels, between two adjacent objects will result in an empty cell or column in Excel output
    3.Make sure that the widths of all objects are vertically consistent.
    Explanation: If the objects are not exactly aligned vertically, that is, have inconsistent widths, it is likely to result in insertion of unwanted cells/columns in Excel.
    4. Pls. Make sure that the vertical elasticity of the frames and repeating frames is not fixed unless you are sure you have allocated enough space to accommodate all the records.
    Explanation: If you set the Vertical Elasticity property of a frame to Fixed, the output in Excel will show only as many records as could appear on the first page of the paper output. Since Excel does not have a page concept, it is not able to overflow the remaining rows to the next page.
    5. For reliable formatting of spreadsheet output, enclose the whole layout area in a frame.
    Explanation: This action prevents the possibility of parallel objects displaying in different vertical positions, one following the other.
    Hope this helps.
    Regards,
    Alex

  • How to export query results

    How can I export query results from sqlplus on the command line? Are there ways to specify the format such as CSV, TAB, XML, etc?
    I've seen one approach that involves creating a shell script and piping the output to a file:
    #!/bin/sh
    sqlplus user/password <<__EOF__
    set heading off;
    set newpage none;
    select f1, ',', f2, ',', f3 from some_table;
    __EOF__
    Then pipe the output to a file. Is there a simpler solution to this?

    http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:235814350980

  • Exporting Query Result to OpenOffice

    Hello,
    We would like to export Query Result from Web Application to a file which could be opened in OpenOffice.
    Exporting data in XLS format doesn't work because XLS file is created with MS VML Markup with couln't be read by OpenOffice.
    Does someone already deals with this kind of issue ?
    How do you overcome this problem ?
    Thanks in advance for your answer
    Laurent

    Hi Laurent,
    Can you try saving the file in .csv.
    ad try opening it in openoffice.
    Hope this helps
    PV

  • How to save query result in excel file

    Hi all,
    How to save query result in excel file from sql*plus tool.
    thank you

    Do you really need an Excel file (binary) or a simple CSV?
    If you just need a CSV then search for DUMP_CSV at http://asktom.oracle.com or at this forum
    If you need formatting and/or multiple worksheets then you can use free tools like
    https://xml-spreadsheet.samplecode.oracle.com/ or https://exceldocumenttype.samplecode.oracle.com/
    Regards
    Marcus

  • Saving query results as excel

    hi,
    Is there a way to save the query results as excel programatically (some kind of utility which does the job)? we are using oracle 10g. This will be a nightly job.. so that every other day morning we have the huge excel report ready for viewing. Any help is appreciated..

    Did you think to try searching the forum? I typed in the EXACT string you used for your thread title and the first hit was ...
    Saving sql query result as excel file

  • How to export data to 2 tabs in excel from form with two tabs

    Hi friends
    i am now faceing a prbs of exporting data to excel to different tabs.
    ex:- i have a multiple records form with two tab . i want to export data corresponding to excel as two tabs.
    can anyone suggest me how can i export data to 2nd tab.. is any functions or procedure to help me .

    Hello,
    at Re: How to save a query result and export it to, say excell? you can find links to different solutions. At least the packages behind second and fourth link support more than one worksheet. And both describe how to do it.
    Regards
    Marcus

  • Export result of ssas query result to excel file

    Hi All,
    I have browsed a SSAS cube. I want to export result of SSAS cube into excel file.
    Kindly give your input.
    Thanks,
    Vivek singh

    Hi,
    I do not know whether there is a direct solution but there is an indirect way of doing it. I always follow this method if I ever want to get MDX results into Excel.
    1 - Install the DAX Studio (I know you want MDX results, so do not get confused by looking at the word DAX. Continue reading). You can download it from the following location.
    http://www.sqlbi.com/tools/dax-studio/
    2 - Once you install DAX Studio, Go to the Add-Ins ribbon. Click on DAX Studio. 
    3 - There is an option "Tabular Server" and there is a drop-down list where you can enter the SSAS (MD CUBE Server) server name. Enter the server name manually. If you have multiple SSAS Databases and if you are interested in a specific SSAS database
    enter "Initial Catalog=Your SSAS Database Name" in Additional Options section and Click Connect. You can successfully connect to the SSAS Server now.
    Here are the details described so far in pictorial representation.
    4 - Enter your MDX manually and execute the code via DAX studio and you will get your results right-away in Excel.
    Now, isn't that an elegant way of getting MDX results into Excel :) ? Besides Excel's Pivot Table option, I do not know whether there are any alternate solutions to this but wait for other Pros' comments as well.
     Best regards...
    Chandima Lakmal Fonseka

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

  • Export query results to flat file with dynamic filename

    Hi
    Can anybody can point me how to dynamic export query serults set to for example txt file using process flows in OWB.
    Let say I have simple select query
    select * from table1 where daterange >= sysdate -1 and daterange < sysdate
    so query results will be different every day because daterange will be different. Also I would like to name txt file dynamicly as well
    eg. results_20090601.txt, results_20090602.txt, results_20090603.txt
    I cant see any activity in process editor to enter custom sql statment, like it is in MSSQL 2000 or 2005
    thanks in advance

    You can call existing procedures from a process flow the procedure can create the filename with whatever name you desire. OWB maps with file as target can also create a file with a dynamic name defined by an expression (see here ).
    Cheers
    David

  • Export query result to txt file

    Hello,
    I'm trying to export a query result to txt file but I facing some problems.
    I'm using the comand below:
    set echo off newpage 0 space 0 pagesize 0 feed off head off trimspool on
    set colsep ,
    spool C:\estados.txt
    select id_estado,cod_estado,nme_estado from tb_estado;
    spool off
    First problem: My select statement is being writen on my estados.txt
    Second problem: The results are being writen with a lot of blank spaces in start of line, for example, instead of write "1,AC,Acre" the line is write as " 1,AC,Acre".
    Third problem: The "spool off" statement is being written on my estados.txt
    How could I solve it?
    Thanks

    1. Works here - what version of SQL*PLUS are you using?
    2. If you want to prevent spaces, you have to write your SELECT like this:
    select id_estado || ',' || cod_estado || ',' || nme_estado from tb_estado;Note: not tested.
    3. See 1.
    C.

  • Export query results to a CSV file

    Hi,
    My requirement is I need to export the results of a query to a CSV file. Can anyone please suggest a way to include the column names also in the CSV file?
    Thanks in advance.
    Annie

    Following code is from asktom. I have modified to include column heading. This will get your desired CSV file for a given query.
    create or replace function  dump_csv( p_query     in varchar2,
                                          p_separator in varchar2
                                                        default ',',
                                          p_dir       in varchar2 ,
                                          p_filename  in varchar2 )
    return number
    AUTHID CURRENT_USER
    is
        l_output        utl_file.file_type;
        l_theCursor     integer default dbms_sql.open_cursor;
        l_columnValue   varchar2(2000);
        l_status        integer;
        l_colCnt        number default 0;
        l_separator     varchar2(10) default '';
        l_cnt           number default 0;
         l_colDesc          dbms_sql.DESC_TAB;
    begin
        l_output := utl_file.fopen( p_dir, p_filename, 'w' );
        dbms_sql.parse(  l_theCursor,  p_query, dbms_sql.native );
        for i in 1 .. 255 loop
            begin
                dbms_sql.define_column( l_theCursor, i,
                                        l_columnValue, 2000 );
                l_colCnt := i;
            exception
                when others then
                    if ( sqlcode = -1007 ) then exit;
                    else
                        raise;
                    end if;
            end;
        end loop;
        dbms_sql.define_column( l_theCursor, 1, l_columnValue, 2000 );
        l_status := dbms_sql.execute(l_theCursor);
         dbms_sql.describe_columns(l_theCursor,l_colCnt, l_colDesc);
         l_separator := '';
         for lColCnt in 1..l_colCnt
         loop          
                utl_file.put( l_output, l_separator ||  '"' || Upper(l_colDesc(lColCnt).col_name) || '"');
                   l_separator := p_separator;
         end loop;
         utl_file.new_line( l_output );
        loop
            exit when ( dbms_sql.fetch_rows(l_theCursor) <= 0 );
            l_separator := '';
            for i in 1 .. l_colCnt loop
                dbms_sql.column_value( l_theCursor, i,
                                       l_columnValue );
                utl_file.put( l_output, l_separator ||  '"' ||
                                        l_columnValue || '"');
                l_separator := p_separator;
            end loop;
            utl_file.new_line( l_output );
            l_cnt := l_cnt+1;
        end loop;
        dbms_sql.close_cursor(l_theCursor);
        utl_file.fclose( l_output );
        return l_cnt;
    end dump_csv;The original link is below.
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:95212348059
    Thanks,
    Karthick.

Maybe you are looking for