OLE for transfer data to excel
Hi
Can any one send me the coding to use ole for sending data from a multirecord form to excel?
I have never used OLE.
i am using DDE package for this task but its very slow.
regards,
adeel
Hi Adeel
Here's some code to dump the contents of a block into Excel. You may want to uncomment the commented-out sections if you want the functionality of being able to save the workbook that gets created. (I copied it a while back from this forum, so am not claiming any credit for it, or for the lack of readability!!)
Best regards
Andrew
PROCEDURE pr_Forms_to_Excel(p_block_name IN VARCHAR2 DEFAULT NAME_IN('system.current_block')) 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;
range OLE2.OBJ_TYPE;
range_col OLE2.OBJ_TYPE;
-- Declare handles to OLE argument lists
args OLE2.LIST_TYPE;
-- Declare form and block items
form_name VARCHAR2(100);
f_block VARCHAR2(100);
l_block VARCHAR2(100);
f_item VARCHAR2(100);
l_item VARCHAR2(100);
cur_block VARCHAR2(100) := NAME_IN('system.current_block');
cur_item VARCHAR2(100) := NAME_IN('system.current_item');
cur_record VARCHAR2(100) := NAME_IN('system.cursor_record');
item_name VARCHAR2(100);
baslik VARCHAR2(100);
row_n NUMBER;
col_n NUMBER;
filename VARCHAR2(100);
BEGIN
-- Start Excel
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');
-- Add a new Workbook object to the Workbooks collection
workbook:=OLE2.GET_OBJ_PROPERTY(workbooks,'Add');
-- Return object handle to the Worksheets collection for the Workbook
worksheets:=OLE2.GET_OBJ_PROPERTY(workbook, 'Worksheets');
-- Get the first Worksheet in the Worksheets collection
-- worksheet:=OLE2.GET_OBJ_PROPERTY(worksheets,'Add');
args:=OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(args, 1);
worksheet:=OLE2.GET_OBJ_PROPERTY(worksheets,'Item',args);
OLE2.DESTROY_ARGLIST(args);
-- Return object handle to cell A1 on the new Worksheet
go_block(p_block_name);
baslik := get_block_property(p_block_name,FIRST_ITEM);
f_item := p_block_name||'.'||get_block_property(p_block_name,FIRST_ITEM);
l_item := p_block_name||'.'||get_block_property(p_block_name,LAST_ITEM);
first_record;
LOOP
item_name := f_item;
row_n := NAME_IN('SYSTEM.CURSOR_RECORD');
col_n := 1;
LOOP
IF get_item_property(item_name,ITEM_TYPE)<>'BUTTON' AND
get_item_property(item_name,VISIBLE)='TRUE'
THEN
-- Set first row with the item names
IF row_n=1 THEN
baslik:=NVL(get_item_property(item_name,PROMPT_TEXT),baslik);
args:=OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(args, row_n);
OLE2.ADD_ARG(args, col_n);
cell:=OLE2.GET_OBJ_PROPERTY(worksheet, 'Cells', args);
OLE2.DESTROY_ARGLIST(args);
OLE2.SET_PROPERTY(cell, 'Value', baslik);
OLE2.RELEASE_OBJ(cell);
END IF;
-- Set other rows with the item values
args:=OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(args, row_n+1);
OLE2.ADD_ARG(args, col_n);
cell:=OLE2.GET_OBJ_PROPERTY(worksheet, 'Cells', args);
OLE2.DESTROY_ARGLIST(args);
IF get_item_property(item_name,DATATYPE)<>'NUMBER' THEN
OLE2.SET_PROPERTY(cell, 'NumberFormat', '@');
END IF;
OLE2.SET_PROPERTY(cell, 'Value', name_in(item_name));
OLE2.RELEASE_OBJ(cell);
END IF;
IF item_name = l_item THEN
exit;
END IF;
baslik := get_item_property(item_name,NEXTITEM);
item_name := p_block_name||'.'||get_item_property(item_name,NEXTITEM);
col_n := col_n + 1;
END LOOP;
EXIT WHEN NAME_IN('system.last_record') = 'TRUE';
NEXT_RECORD;
END LOOP;
-- Autofit columns
range := OLE2.GET_OBJ_PROPERTY( worksheet,'UsedRange');
range_col := OLE2.GET_OBJ_PROPERTY( range,'Columns');
OLE2.INVOKE( range_col,'AutoFit' );
OLE2.RELEASE_OBJ( range );
OLE2.RELEASE_OBJ( range_col );
-- Get filename and path
args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG( args, p_block_name );
OLE2.ADD_ARG( args,'Excel Workbooks (*.xls, *.xls');
filename := OLE2.INVOKE_CHAR( application,'GetSaveAsFilename',args );
OLE2.DESTROY_ARGLIST( args );
-- Save as worksheet
IF NVL(filename,'0')<>'0' THEN
args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG( args,filename );
OLE2.INVOKE( worksheet,'SaveAs',args );
OLE2.DESTROY_ARGLIST( args );
END IF;
-- Close workbook
--OLE2.INVOKE( workbook ,'Close');
-- Release the OLE objects
OLE2.RELEASE_OBJ(worksheet);
OLE2.RELEASE_OBJ(worksheets);
OLE2.RELEASE_OBJ(workbook);
OLE2.RELEASE_OBJ(workbooks);
--OLE2.INVOKE(application, 'Quit');
OLE2.RELEASE_OBJ(application);
-- Focus to the original location
go_block(cur_block);
go_record(cur_record);
go_item(cur_block||'.'||cur_item);
END;
Similar Messages
-
Transfer Data from excel to text file or SAP R/3
Hi,
Can anyone please let me know if there is any function module to transfer data from excel to a .txt file.
I am using a CRM 5.0 system and some standard SAP function modules are missing.
I want to fetch data from excel to SAP R/3.
Wish you great time.
Best Regards
SidHi Sid,
extracting data from an excel sheet to SAP u can use the function module GUI_UPLOAD.
I am providing u its parameters also as it might be useful to u.
The mandatory fields here are FILENAME n in TABLES (in which u will be saving ur data).
and also if u need to download from sap to any file u can use GUI_DOWNLOAD in which u can save data in both excel or txt file.
U can also use SAP_CONVERT_TO_TEX_FORMAT function module to convert into text file.
Rewards would be highly appreciated. Thanks.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME =
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = ' '
HEADER_LENGTH = 0
READ_BY_LINE = 'X'
DAT_MODE = ' '
CODEPAGE = ' '
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
CHECK_BOM = ' '
VIRUS_SCAN_PROFILE =
NO_AUTH_CHECK = ' '
IMPORTING
FILELENGTH =
HEADER =
TABLES
DATA_TAB =
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_READ_ERROR = 2
NO_BATCH = 3
GUI_REFUSE_FILETRANSFER = 4
INVALID_TYPE = 5
NO_AUTHORITY = 6
UNKNOWN_ERROR = 7
BAD_DATA_FORMAT = 8
HEADER_NOT_ALLOWED = 9
SEPARATOR_NOT_ALLOWED = 10
HEADER_TOO_LONG = 11
UNKNOWN_DP_ERROR = 12
ACCESS_DENIED = 13
DP_OUT_OF_MEMORY = 14
DISK_FULL = 15
DP_TIMEOUT = 16
OTHERS = 17
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF. -
ALV FUNCTION MODLE FOR GETTING DATA IN EXCEL SHEET
HI ,
CAN I HAVE ALV FUNCTION MODLE FOR GETTING DATA IN EXCEL SHEET
Regards,
ArunaStandard ALV grid uses the FM <b>ALV_XXL_CALL</b> for exporting data into Excel. You can put a break-point in the FM and check it for urself.
for ur info - the above FM takes the internal table name, internal table content and the field catalog as input. -
Error in CLOB datatype for transfering data from Excel to Oracle database
Am using excel sheet as source and Oracle as target Database.
For all tables the operations works smoothly except for tables containing CLOB datatype.
Initially i have used SQL Developer to transfer some data into excell sheets, now i want to transfer those file's data into another Oracle Database.
What other options do i have?
Is excel not the right tool to transfer CLOB datatypes?well,
I couldn't suggest an excel to do it...
You can go from Oracle to Oracle with the PL/SQL IKM. It works fine.
Does it help you? -
To transfer data in excel sheet..
hi experts,
please let me know how do we transfer the sap data to excel sheet?...using any method..
thanks in advance...Hi,
If you are using ALV there should be an icon
( F9 Function ) for download to spreadsheet
also using GUI_DOWNLOAD FM also you can download data into word ,excel or in rtf or html format
and u want to ur data frm aplication server then use dataset concepts
regards
Santosh L... -
How to transfer data from excel files into z-tables
Please help me with a code which transfers data from excel file to z-table.
Thanks in advance
ShuvirHi Daniel,
Export Data
Purpose
Use this procedure to export SAP data to a local file such as Microsoft Excel.
Menu Path
Use the following menu path to begin this process:
· SystemèListèSaveèLocal File
Helpful Hints
When reviewing fields, R = Required, O = Optional and C = Conditional.
Procedure
1. Start the transaction using the menu path or transaction code.
Whatever Data You Want to Export
2. Select SystemèListèSaveèLocal File. This works well for any data in SAP. This is the only option for the top-level (first page) of a report.
In a drill-down view within a report the Local File button on the toolbar may be used and has the same options.
Choose File Format
3. Click .
4. Click to continue. If prompted for a format after choosing Spreadsheet, select Excel Table to get an Excel file that can be modified more easily.
Choose File Save Location Step 1
5. Click to the right of the Directory field to choose a different location.
Choose File Save Location Step 2
6. Click or browse your computer to locate the directory where you want to save your file.
7. Complete the following field:
· File name:
You must add the proper file extension to the name of your file (.xls for Excel, .rtf for Rich Text, .html for HTML). The file extension tells your computer what program to open the file with. If you do not have the file extension at the end, you may not be able to open it.
8. Click to continue.
Generate File in Location and Format Selected
9. Click to create the file in the location and format selected. In this example the file was named "example.xls" and saved on the desktop.
Result
You have completed the export process.
thanks
karthik -
Problem while executing app for retrieving data from EXCEL Sheet
hi
i have this exception while running my application of retrieving data from a Excel sheet through java application , i had also set theclasspath for jxl. jar file but where its going wrong i dont know heres my code
import java.util.Date;
import java.io.*;
import jxl.*;
import javax.swing.*;
import java.awt.*;
import jxl.read.biff.BiffException;
public class testExcel2
public static void main(String args[]) throws jxl.read.biff.BiffException
try
File f=new File("move.xls");
jxl.Workbook workbook=null;
jxl.Sheet sheet=null;
workbook=jxl.Workbook.getWorkbook(f);
sheet=workbook.getSheet(0);
Cell a1 = sheet.getCell(0,0);
String stringa1 = a1.getContents();
System.out.println("stringshaddddddddjk "+stringa1);
workbook.close();
}catch(IOException ex){
System.out.println("Error" + ex);
catch (BiffException ex2){
System.out.println("Error" + ex2);
catch(IndexOutOfBoundsException ex1){
System.out.println("Error" + ex1);
compilation is sucees but while running its giving an EXCeption
MicrosoftXP[Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
G:\mysfw\pgms>java testexcel2
Exception in thread "main" java.lang.NoClassDefFoundError: testexcel2 (wrong nam
e: testExcel2)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)Java is case sensitive. testexcel2 is different from testExcel2.
G:\mysfw\pgms>java testexcel2
Exception in thread "main" java.lang.NoClassDefFoundError: testexcel2 (wrong name: testExcel2) -
Procedure for transfer data between clients using ALE
Hi all ,
I am new to this concept .
I want to transfer the material master data from quality client (200) to Development Client(100) using ALE and IDOC, how to do ?
What would be the procedure ? plz let them explain step by step of definition along with screenshot / process ....
Regards
Deepa.T.Code: BD54
Step 1:create a logical system qaout in quality system
Step 2:create a logical system devin in quality system
Step 3:create a logical system qaout in development system
Step 4:create a logical system devin in development system
T.Code: SCC4
Step 5:Assign qaout to 200 client in quality system
Step 6:Assign qaout to 100 client in development system
T.Code: SM59
Step 7: Create R/3 type (or ABAP type in ECC)RFC destination RFCDEV in quality system
T.Code: WE21
Step 8: create Port with above rfc reference in quality system
T.Code:BD64
Step 9:Create distribution Model (use matmas message type) in quality system
then Environment ->Generate Partner profiles
Then Edit ->modelview -> distribute
T.Code: BD10
Step 10: select the material for distribution in Quality System. -
Table Technical settings for transfer data from developemnt to Quality
Hi All,
Please let me know which table techinical settings required for to transport table with data from development to quality?
Thanks & Regards,
padmaja.Hi,
You do not require technical settings to transport data from dvlpmnt to quality.
However, you can transport any tables entries with a simple trick:
(1) Create a workbench request
(2) Change the request (or its task) and add the following entry: R3TR TABU <name of table> =>
(3) Enter the key values you want to transport, e.g.:
- <client>* for all entries of the current client
- add additional restrictions for the table entry (<client><bukrs>* for all entries of a given company code)
Best regards,
Prashant -
Hy!
I have a table control with a button SORT and I want the result of pushing this button to be put in an Excel file ( the sorted records).
Any suggestions ?
Many thanks.check the sy-ucomm. or okcode.
if sy-ucomm = 'SORT'.
sort the internal table.
call gui_download. -
Transfer data from MS Excel to Oracle table
Hello,
hope someone can help: What is the easiest way to transfer data from Excel sheet to a Oracle table and how ?
An example of a row to transfer is given below
Date Time Value 1 Value 2
2004-02-02 03:47:39 9,62 3,62
Thanks in advance
Regards
RoarFrom Microsoft access , import data from Excel to an Access table.
Format that Access Table properly in Design mode.
Create a table as per your specification in oracle Database.
Then export to oracle from access using approppriate ODBC driver.
--Sayan -
Upload data from excel (not the excle file) into SAP
Guys,
how can we upload data from excel sheet into SAP? I mean just the data not the entire file,
I have a requirement where user press a button in excel sheet and the data in the sheet will get uploaded into SAP.
I am sure we have to use BAPI and some VB programming for macros, I will really appriciate if anyone can help how to achive this.
some sample code exampe will help.
Cheers!I think u r writing BDC for Uploading the data from excel flile to sap. for this is the code I am sending u can use then for Uploading data from excel to sap.
DATA: lv_filename TYPE rlgrap-filename.
FIELD-SYMBOLS : <fs>.
DATA : l_intern TYPE alsmex_tabline OCCURS 0 WITH HEADER LINE.
DATA : l_index TYPE i.
PARAMETERS : startcol TYPE i ,
startrow TYPE i ,
endcol TYPE i ,
endrow TYPE i .
PARAMETERS: p_flnam LIKE rlgrap-filename.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_flnam.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = sy-repid
FIELD_NAME = ' '
IMPORTING
file_name = p_flnam .
MOVE p_flnam TO lv_filename.
Uploading the flat file from the desktop
START-OF-SELECTION.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = lv_filename
i_begin_col = startcol
i_begin_row = startrow
i_end_col = endcol
i_end_row = endrow
TABLES
intern = l_intern
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
OTHERS = 3
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
SORT l_intern BY row col.
LOOP AT l_intern.
MOVE l_intern-col TO l_index.
ASSIGN COMPONENT l_index OF STRUCTURE itab TO <fs>.
MOVE l_intern-value TO <fs>.
AT END OF row.
APPEND itab.
CLEAR itab.
ENDAT.
ENDLOOP.
I hope it will help u.
Regards
Nayan -
Problem in exporting data to excel in nwds 7.3
Hi All,
I was using the following code for exporting data to excel in NWDS 7.3
private IWDCachedWebResource getCachedWebResource(byte[] file, String name,
WDWebResourceType type) {
IWDCachedWebResource cachedWebResource = null;
if (file != null) {
cachedWebResource = WDWebResource.getWebResource(file, type);
cachedWebResource.setResourceName(name);
return cachedWebResource;
I was getting the error in the following line cachedWebResource = WDWebResource.getWebResource(file, type); when I clicked the quick help it ststed the getWebResource method is depricated. Kindly provide some assistance on what is the new method in its place.
Thank you
Regards,
Preet KaurHi Ganesh,
Thanks that worked fine, but when we go further we are facing problem ie
byte[] excelXMLFile;
IWDCachedWebResource cachedExcelResource = null;
String fileName = dataNode.getNodeInfo().getName() + ".xls";
try {
// create Excel 2003 XML data as a byte array for the given context node,
// attributes and headers
excelXMLFile = toExcel(dataNode, columnInfos).getBytes("UTF-8");
// create a cached Web Dynpro XLS resource for the given byte array
// and filename
cachedExcelResource = getCachedWebResource(
excelXMLFile, fileName, WDWebResourceType.XLS);
// Store URL and file name of cached Excel resource in context.
if (cachedExcelResource != null) {
wdContext.currentContextElement().setExcelFileURL(
cachedExcelResource.getURL());
wdContext.currentContextElement().setExcelFileName(
cachedExcelResource.getResourceName());
// Open popup window with a link to the cached Excel file Web resource.
openExcelLinkPopup();
} else {
wdComponentAPI.getMessageManager().reportException(
"Failed to create Excel file from table!", true);
} catch (UnsupportedEncodingException e) {
wdComponentAPI.getMessageManager().reportException(
e.getLocalizedMessage(), true);
} catch (WDURLException e) {
wdComponentAPI.getMessageManager().reportException(
e.getLocalizedMessage(), true);
The above bold lines also would need to be converted to inputstream, but not sure how to correct that
We are following the below pdf for the implementation.
http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/edc2f3c2-0401-0010-8898-acd5b6a94353?QuickLink=index&overridelayout=true
Thank you
Regards,
Jaspreet Kaur -
How to Download Data in Excel Formate
Hi Friend,
I have one doubt on webdynpro with java. Req: For download data in Excel formate.
I will follow this http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/3596. [original link is broken] [original link is broken] [original link is broken]
i am doing upto 3rd Step here.. Up to Step 3 i am doing after 3rd Step I am not understand. Could u explain 4step.
1. I have to place TableUtilities.java
2. I have Create tableutilities value attribute
3. in Modify view--- This is -SecondView -
This is having Table UI Element.
if(firstTime)
IWDTextView tv = (IWDTextView)view.getElement("total");
wdContext.currentContextElement().setTableutility(new TableUtilities(wdContext.nodeDepartments()));
//Returns attribute info of a dynamically created attribute which can be bound to the UI element neeed.
tv.bindText(wdContext.currentContextElement().getTableutility().CalculateSum("Departments","NoOfPeople"));
4. Creating an Excel File
How to Create Excel File here can u explain
I am not understand this 4th step. Pls give me Breef Explanation. How to write this code...here...
Regards
Vijay Kalluri
Edited by: KalluriVijay on May 4, 2010 8:00 PM
Edited by: KalluriVijay on May 4, 2010 8:02 PMHi Vijay,
Please open Microsoft Excel from your system and then create some entries (ex. having 3 columns and 3 rows). Save this file to some location in your system. Later you will need to give the location path of this saved file when uploading it from your web dynpro application.
Creating of an Excel file (i.e the 4th step) is no where related to Web Dynpro and NWDS.
Hope this helps!
Regards,
Kishan -
I have been using sql*loader to transfer data
from Excell to Oracle8. Now I need to do the reverse. I need to take data from Oracle back to Excell. Coould someone tell me how to do that or at least start me in the right direction ?
Thanks,
JordiThanks Andrew. I was hoping there was a way to save the Oracle data as a text file which I could then load into Access or Excell. I will however try your suggestion.
Thanks !
<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Andrew Jones:
Try ODBC.
Data -> Get External Data -> New Database Query<HR></BLOCKQUOTE>
null
Maybe you are looking for
-
Re: [REQ] Memory flag or way to monitor DB(dis)connections
Presumably on Mon, 20 Jul 1998 17:29:29 +0200 Jean-Paul wrote: [snip] We're currently running an application with some DBSession Service Objects. As in both code and partition workshop the parameter 'password' is hidden (replaced with ***), we can't
-
Repairing disk permissions gives me this -
Does anyone know what this means? I ran disc utility and repaired permissions and this shows up every time. Warning: SUID file "System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/MacOS/ARDAg ent" has been modified and will not be repa
-
160gb SATA not detected while 80gb SATA is working fine
I have a MSI K8MM-V board with AMD 2800+, I am alredy using a 80gb SATA1 drive, I recently purchased a 160gb SATA1 (seagate) however, to my surprise the disk is not being detected in the BIOS and even when I suply the drivers during windows xp instal
-
Hello All Error on Export Button: When i click the export button, I get the following error: InvalidObjNameException: JBO-25005: Object name for type View Object is invalid Can any help telling what the error is about. Regards
-
my mac air keeps saying plug in failure ,,downloaded latest adobe .and checked its enabled help please