Writing data from a table to Excel file
Hello friends,
I am using Forms 5.0 on Windows NT. I need to write data from table A to Excel sheet from trigger 'when-botton-pressed'. Could you help me Any help will be appriciated.
Thanks
Charg
null
HERE IS THE CODE.
YOU CAN RUN IT USING THE DEPT TABLE.
PROCEDURE export_transaction_to_excel IS
application ole2.obj_type;
workbooks ole2.obj_type;
workbook ole2.obj_type;
worksheets ole2.obj_type;
worksheet ole2.obj_type;
cell ole2.obj_type;
fdes varchar2(250);
rowcounter number:=1;
local_cursor_record number:=:system.cursor_record;
old_cursor_style varchar2(100);
errors_occured boolean:=false;
ole_error exception;
pragma exception_init(ole_error, -305500);
my_alert_id alert;
alert_respnse number;
procedure place_value_in_cell(rownum_in in number,colnum_in in number,value_in in varchar2) is
args ole2.list_type;
begin
args:=ole2.create_arglist;
ole2.add_arg(args,rownum_in);
ole2.add_arg(args,colnum_in);
--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
fdes:='C:\TESTFORM.XLS';
vDatestamp:=to_char(sysdate,'mmddyyyyy')| |'-'| |to_char(sysdate,'hh24miss');
args:=ole2.create_arglist;
ole2.add_arg(args,fdes);
ole2.invoke(worksheet,'SaveAs',args);
ole2.destroy_arglist(args);
ole2.invoke(application,'Quit');
end savespreadsheet;
procedure open_excel_workbook is
begin
application:=ole2.create_obj('Excel.Application');
workbooks:=ole2.get_obj_property(application,'Workbooks');
workbook:=ole2.invoke_obj(workbooks,'Add');
worksheets:=ole2.get_obj_property(application,'Worksheets');
worksheet:=ole2.invoke_obj(worksheets,'Add');
end open_excel_workbook;
procedure write_column_header is
begin
place_value_in_cell(rowcounter,1,'Depart No');
place_value_in_cell(rowcounter,2,'Depart Name');
place_value_in_cell(rowcounter,3,'Loc');
rowcounter:=rowcounter+1;
end write_column_header;
procedure export_the_data is
original_receipt number;
original_date date;
original_transmital_number number;
begin
go_block('dept');
first_record;
loop
place_value_in_cell(rowcounter,1,to_char(:deptno));
place_value_in_cell(rowcounter,2,:dname);
place_value_in_cell(rowcounter,3,:loc);
exit when :system.last_record='TRUE';
next_record;
rowcounter:=rowcounter+1;
end loop;
end export_the_data;
BEGIN
begin
old_cursor_style:=get_application_property(cursor_style);
set_application_property(cursor_style,'BUSY');
open_excel_workbook;
write_column_header;
export_the_data;
exception
when form_trigger_failure then
raise;
when ole_error then
message('error sending data to excel');
message(' ');
errors_occured:=true;
end;
savespreadsheet;
ole2.release_obj(worksheet);
ole2.release_obj(worksheets);
ole2.release_obj(workbook);
ole2.release_obj(workbooks);
ole2.release_obj(application);
if not errors_occured then
go_record(local_cursor_record);
end if;
set_application_property(cursor_style,old_cursor_style);
END export_transaction_to_excel;
Similar Messages
-
Writing Data from a Table to Excel
Hi Experts
I have a requirement to load data from an Oracle Table to an excel File. I was able to use OdiSqlUnload to achieve this, but the problem is I am not getting Header Information in my Excel. Please advise if there is any other method through which I can achieve this.
ThanksHi,
Create a datastore in the file tecnology and make it delimited by ";".
After that create an interface from table to it.
In the IKM, you can chose to generate the header
OR
Use 2 OdiSqlUnload where the first just create the file and the header (a select column name from dual where column names are constants ) and the 2 append the real data
Make any sense? -
How can i extract data from oracle table to flat file or excel spread shee
Hello,
DB Version is 10.1.0.3.0
How can i extract data from oracle table to flat file or excel spread sheet by using sub programs?
Regards,
DHere what I did
SET NEWPAGE 0
SET SPACE 0
SET LINESIZE 80
SET PAGESIZE 0
SET ECHO OFF
SET FEEDBACK OFF
SET VERIFY OFF
SET HEADING OFF
SET MARKUP HTML OFF SPOOL OFF
Sql> SPOOL bing
select * from -------;
SPOOL OFF;
I do not see file.
I also tried
Sql> SPOOL /tmp/bing
select * from -------;
SPOOL OFF;
But still not seeing the fie, -
Gui_download for transferring the data from internal table to excel sheet.
hi all,
i am using gui_download for transferring the data from internal table to excel sheet.
I have a internal table with 3 columns col1,col2,col3 and I am getting the file at the specified path,but my problem is that,in the excel sheet(path specified) all the 3 columns values are printed in one column.Please help me.
Thanks in advance.Hi Venkata,
plz use FM 'SAP_CONVERT_TO_XLS_FORMAT' :
call function 'SAP_CONVERT_TO_XLS_FORMAT'
exporting
* I_FIELD_SEPERATOR =
* I_LINE_HEADER =
i_filename = p_file
* I_APPL_KEEP = ' '
tables
i_tab_sap_data = t_mbew
* CHANGING
* I_TAB_CONVERTED_DATA =
* EXCEPTIONS
* CONVERSION_FAILED = 1
* OTHERS = 2
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
Hope this helps,
Erwan -
Downloading data from internal table to xls file leading zeros are not disp
Hai abap gurus,
when i am downloading data from internal table to excle file. some field values in a column are with leading zeros and some others dont have leading zeros.but in the output it is showing without leading zeros. then how to get with exact values.
Ex:
<b>ECC Code.</b>
045234
88567
098456
but output is giving like this:
45234
88567
98456
how to get the actual values.....
plz help me in this matter.Dear Kiran,
Those field in the internal table having Leading Zeroes, make those fields' datatype as character.
Then use the function module to download the content of the internal table to the excel file.
Regards,
Abir
Don't forget to Reward Points * -
Download data from internal table to flat file.
I need to download the data from Internal table to Flat file. can any one suggest how to do it? i suppose WS_Download OR GUI_DOWNLOAD.
but if it is please guide me how to use this.
is thre any other F.M. please provide the information.
Thanks in advanceHi,
Try this,
* File download, uses older techniques but achieves a perfectly
* acceptable solution which also allows the user to append data to
* an existing file.
PARAMETERS: p_file like rlgrap-filename.
* Internal table to store export data
DATA: begin of it_excelfile occurs 0,
row(500) type c,
end of it_excelfile.
DATA: rc TYPE sy-ucomm,
ld_answer TYPE c.
CALL FUNCTION 'WS_QUERY'
EXPORTING
query = 'FE' "File Exist?
filename = p_file
IMPORTING
return = rc.
IF rc NE 0. "If File alread exists
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
* TITLEBAR = ' '
* DIAGNOSE_OBJECT = ' '
text_question = 'File Already exists!!'
text_button_1 = 'Replace'
* ICON_BUTTON_1 = ' '
text_button_2 = 'New name'
* ICON_BUTTON_2 = ' '
* DEFAULT_BUTTON = '1'
* DISPLAY_CANCEL_BUTTON = 'X'
* USERDEFINED_F1_HELP = ' '
* START_COLUMN = 25
* START_ROW = 6
* POPUP_TYPE =
IMPORTING
answer = ld_answer
* TABLES
* PARAMETER =
EXCEPTIONS
text_not_found = 1
OTHERS = 2.
* Option 1: Overwrite
IF ld_answer EQ '1'.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
* BIN_FILESIZE =
filename = p_file "File Name
filetype = 'ASC'
* IMPORTING
* FILELENGTH =
TABLES
data_tab = it_excelfile "Data table
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE i003(zp) WITH
'There was an error during Excel file creation'(200).
exit. "Causes short dump if removed and excel document was open
ENDIF.
* Option 2: New name.
ELSEIF ld_answer EQ '2'.
CALL FUNCTION 'DOWNLOAD'
EXPORTING
filename = p_file "File name
filetype = 'ASC' "File type
* col_select = 'X' "COL_SELECT
* col_selectmask = 'XXXXXXXXXXXXXXXXXXXXXXXXXX'
* "COL_SELECTMASK
filetype_no_show = 'X' "Show file type selection?
* IMPORTING
* act_filename = filename_dat
TABLES
data_tab = it_excelfile "Data table
* fieldnames =
EXCEPTIONS
file_open_error = 01
file_write_error = 02
invalid_filesize = 03
invalid_table_width = 04
invalid_type = 05
no_batch = 06
unknown_error = 07.
ENDIF.
ELSE. "File does not alread exist.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
* BIN_FILESIZE =
filename = p_file "File name
filetype = 'ASC' "File type
* IMPORTING
* FILELENGTH =
TABLES
data_tab = it_excelfile "Data table
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE i003(zp) WITH
'There was an error during Excel file creation'(200).
exit. "Causes short dump if removed and excel document was open
ENDIF.
ENDIF.
Regards,
Raghav -
How to retrieve data from a read-only Excel file
Hi Developers,
I'm trying to retrieve data from a read-only Excel file. I used the same code that I used to retrieve data from a normal Excel file, but it can't work.
My code is as followed:
try
InputStream KpExcel = new FileInputStream("kp.xls");
HSSFWorkbook Kpwb = new HSSFWorkbook(KpExcel);
HSSFSheet Kpsheet = Kpwb.getSheetAt(0);
catch(Exception e)
e.printStackTrace();
System.out.println("Exception: "+e.getMessage());
The error I received is as followed:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
at org.apache.poi.hssf.record.RecordFactory.createRecord(RecordFactory.java:224)
at org.apache.poi.hssf.record.RecordFactory.createRecords(RecordFactory.java:160)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:163)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:210)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:191)
at photoproductionsystem.IncomingWIPPanel.getKp(IncomingWIPPanel.java:118)
at photoproductionsystem.IncomingWIPPanel.<init>(IncomingWIPPanel.java:76)
at photoproductionsystem.TabbedDisplay.<init>(TabbedDisplay.java:47)
at photoproductionsystem.Display.create(Display.java:73)
at photoproductionsystem.Display.init(Display.java:44)
at photoproductionsystem.Display.main(Display.java:229)
Caused by: java.lang.ArrayIndexOutOfBoundsException
at java.lang.System.arraycopy(Native Method)
at org.apache.poi.hssf.record.UnknownRecord.<init>(UnknownRecord.java:62)
at org.apache.poi.hssf.record.SubRecord.createSubRecord(SubRecord.java:57)
at org.apache.poi.hssf.record.ObjRecord.fillFields(ObjRecord.java:99)
at org.apache.poi.hssf.record.Record.fillFields(Record.java:90)
at org.apache.poi.hssf.record.Record.<init>(Record.java:55)
at org.apache.poi.hssf.record.ObjRecord.<init>(ObjRecord.java:61)
... 15 more
Can someone please help me with my problem? Thanks a lot in advance!Madeline wrote:
how do I ask at Apache mailing list?I wonder why it seems to be a strange idea to some people to look at the software vendor's site for product support. :p
http://poi.apache.org/mailinglists.html -
In PL-SQL archive data from a table to a file
I am currently developing a vb app where I need to archive data from a table to a file. I was hoping to do this with a stored procedure. I will also need to be able to retrieve the data from the file for future use if necessary. What file types are available? Thanks in advance for any suggestions.
What about exporting in an oracle binary format? The export files cannot be modifiable. Is there a way to use the export and import utility in PL/SQL?
null -
Upload data from multiple worksheets of excel file into SAP by using MIME?
Hi all,
I'm trying to getting the data from a multiple worksheet excel file by usin the MIME Repository.
First of all i realizied it like [here|http://abap-explorer.blogspot.com/2008/12/upload-data-from-multiple-worksheets-of.html] in a normal ABAP Report.
By trying to transfer the code to a WebDynpro Component, i get problems.
With this part of code, because ActiveX is not allowed in our Webbrowser. So i have to find another solution to get the data from the excel file.
CALL METHOD c_oi_container_control_creator=>get_container_control
IMPORTING
control = iref_control
error = iref_error
I tried to rebuild this solution in webdynpro. But it dont works.
So my next step was trying to Read the Excel sheet directly from MIME by getting the Content (XString).
But there is no useful information Just a mix out of '######' and other symbols.
By converting it into String the same problem.
Maybe someone has an idea how to rebuild [this code|http://abap-explorer.blogspot.com/2008/12/upload-data-from-multiple-worksheets-of.html] in Webdynpro that it works correctly.
Currently Im Using the Fileupload UI Element. All Works fine. I can Upload the Excel file to MIME Repository and i can open it from there.
But i cant get the same clear informationen from the file, to write it later in a Database, like before without webdynpro.
i hope someone can help me.
Edited by: Sascha Baumann on Apr 20, 2009 4:28 PMYou can't read the native binary Excel Format in server side ABAP. The functions and classes that did this in Classic Dynpro used OLE Automation via the SAPGUI Control Framework to remotely control Excel to read the data. Because in the browser you have no connection to the SAPGUI or are sandboxed inside the browser; the same functionality is not possible.
I would suggest that you look into saving the Excel file as a open, text format. You might be able to use XML (although the Excel XML format can be complex) to support multiple sheets. You would have to build the logic yourself (using XSLT or the iXML parser) to process the XML format back into ABAP data. -
Convert data from internal table to XML file.
Hi All,
I am selecting data from database into one internal table.
Now I want to convert data from internal table to xml file format and save in to my desktop. Please suggest me how I can achieve my requirement.
Kindly reply me ASAP.Use this FM. SAP_CONVERT_TO_XML_FORMAT
Check this link too -
Re: Data Export in XML format
XML files from ABAP programs -
Upload data from Internal table to text file with '~' separator
can anyone help me to download data from internal table to flat file with '' separator. GUI_DOWNLOAD is not working in my case ....like for '' separator
Here it is
REPORT zkb_test1.
TYPE-POOLS: truxs.
DATA: i_scarr TYPE TABLE OF scarr,
i_conv_data TYPE truxs_t_text_data.
SELECT * FROM scarr INTO TABLE i_scarr.
CALL FUNCTION 'SAP_CONVERT_TO_TEX_FORMAT'
EXPORTING
i_field_seperator = '~'
TABLES
i_tab_sap_data = i_scarr
CHANGING
i_tab_converted_data = i_conv_data
EXCEPTIONS
conversion_failed = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
filename = 'C:\Test1.txt'
filetype = 'ASC'
CHANGING
data_tab = i_conv_data
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
not_supported_by_gui = 22
error_no_gui = 23
OTHERS = 24.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Regards
Kathirvel -
FM to get Data from Sheet of an excel file to Internal table??
Hello Champs!!!
I have a problem in Excel File's Data Getting.
There are diffrent Sheets in a single Excel file. I need data of a perticular sheet into an internal Table.
Like there are 2 Sheets in an Excel file EXCEL1, Sheet1 & Sheet2. Both Sheet have diffrent Data in it.
Now i only need Data of Sheet1 of this Excel FIle Excel1.
How can i get it?
Can you please help me in this?
Thanks in Advance!!!!
Girija ShankarWelcome to SCN
Please search before you post next time:BDC, upload data from multi excel sheets -
Store data from a table into excel sheet and email
Hi all,
I am just wondering, i m not sure where to start. I want to insert data from a table into an excel spread sheet.
I'm working on a stored procedure with 3 input parameters:
1. the actual query
2. userid
3. the column headers (comma separated) - these will be in the same order as the outer select statement in the query itself. I will use the column headers for the respective columns in Excel worksheet.
When the proc is executed, the excel is populated. If the record count is > 65536, then I need to create multiple worksheets in the same excel file.
How can i do that? Can any body please help with this..?We are doing like this ( Not sure whether it is the best method available)
--Get the output of the query (Since the number of columns is not fixed you would have to use dbms_sql package)
--loop through the output and write into a file, for example test.csv, using UTL_FILE package
--load the file into a blob variable(we are doing it by loading it into a table)
--For mailing You can use the below package
http://www.oracle.com/technology/sample_code/tech/pl_sql/htdocs/Utl_Smtp_Sample.html
Mailing code we are using is given below:
CREATE OR REPLACE procedure xls_mail(
p_sender varchar2, -- sender, example: 'Me <[email protected]>'
p_recipients varchar2, -- recipients, example: 'Someone <[email protected]>'
p_subject varchar2, -- subject
p_text varchar2, -- text
p_filename varchar2, -- name of xls file
p_blob blob -- xls file
) is
conn utl_smtp.connection;
i number;
len number;
BEGIN
conn := demo_mail.begin_mail(
sender => p_sender,
recipients => p_recipients,
subject => p_subject,
mime_type => demo_mail.MULTIPART_MIME_TYPE);
demo_mail.begin_attachment(
conn => conn,
mime_type => 'application/xls',
inline => TRUE,
filename => p_filename,
transfer_enc => 'base64');
-- split the Base64 encoded attachment into multiple lines
i := 1;
len := DBMS_LOB.getLength(p_blob);
WHILE (i < len) LOOP
IF(i + demo_mail.MAX_BASE64_LINE_WIDTH < len)THEN
UTL_SMTP.Write_Raw_Data (conn
, UTL_ENCODE.Base64_Encode(
DBMS_LOB.Substr(p_blob, demo_mail.MAX_BASE64_LINE_WIDTH, i)));
ELSE
UTL_SMTP.Write_Raw_Data (conn
, UTL_ENCODE.Base64_Encode(
DBMS_LOB.Substr(p_blob, (len - i)+1, i)));
END IF;
UTL_SMTP.Write_Data(conn, UTL_TCP.CRLF);
i := i + demo_mail.MAX_BASE64_LINE_WIDTH;
END LOOP;
demo_mail.end_attachment(conn => conn);
demo_mail.attach_text(
conn => conn,
data => p_text,
mime_type => 'text/html');
demo_mail.end_mail( conn => conn );
END; -
How to copy datas from a table to a file.
Hi,
Can Someone help me how to do this using queries or procedures.
I want to copy the datas from the table to a flat file (eg. text or excel).
example:
CREATE TABLE emp
(FCST_DATE DATE,
LEVEL1 VARCHAR2(2000) ,
Sal NUMBER,
Insert into emp (FCST_DATE,LEVEL1,Sal) values ('01-MAR-11','175-12','1');
Insert into emp (FCST_DATE,LEVEL1,Sal) values ('01-JAN-11','319-10','100');
Insert into emp (FCST_DATE,LEVEL1,Sal) values ('01-AUG-11','175-1L','10');
select * from emp;
fcst_date Level1 Sal
01-JAN-11 319-10 100
01-AUG-11 175-1L 12
01-MAR-11 175-12 1
I want this table information in a file.
Can someone help!
PadmaHi Padu,
Use SQLPLUS commad SPOOL for exporting sql query result.
and see : Sqlplus – spool data to a flat file -
How to Export data from a Table to Excel using PL/SQL Code
Hi,
I need to export data from a table to the excel sheet using PL/SQL script.
could you pls provide with custom codes or sample procedures.
Bobbyhttp://asktom.oracle.com/pls/ask/f?p=4950:8:7947129213057862756::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:728625409049
Maybe you are looking for
-
Allignment problem between Report Builder And Apps
Hi All : If i am running a report in report builder i am getting 20 records in each page of the reports.but when i am running this same report in apps i am getting 24 records in each page of the apps more than this the records allignment everything h
-
Missing Sparsity Advisor in AWM, how to get/activate this function?
hi all, I use "Analytic Workspace Manager 10.2.0.3.0A" to create my cubes and dimensions. In the Demonstration of "Analytic Workspace Manager 10.2.0.3.0", I seen there is the function "Sparsity Advisor" in AWM. But I don't found this function in my "
-
Help! I've lost all my music
Help! I've lost all my music! I moved abroad and copied all of my cds to my new ipod touch 3rd. Old computer stored in states. Now I'm in Italy with a new laptop. and when I signed decided to down an app, i had to reinstall itunes, not only did i fai
-
Data acquisition over a window
I am trying to acquire data using LABVIEW 2009 from NI- PCI 6024E DAQ. The data has to be acquired every 10 sec, over a 2 sec window @ 1KHz. That means, the data is acquired @ 1KHz only at t= 9-11s, 19-21 s, 29-31 s and so on. The average value o
-
Good Sunday everyone, I am a newbie in SAP BI and having a problem understanding the concept of usage types. For an example, what does it mean that BI is a usage type? I've read that SAP implementations are based on usage type and not components....