Reading current workbook in Excel
Hi,
I am trying to read from an ABAP report, using OLE automation, some cells from the currently opened workbook. I don't want to ask the user where the file is, but just read the currently opened file.
I was successful to activate the Excel application, but I didn't find a way to access an already opened file. The examples cover only the opening of a file from disk.
Any hint?
got it
read the 'item 1' from this following registry entry
HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Excel\File MRU
check methods from cl_gui_frontend_services to get the registry value(search SDN otherwise).
this ITEM 1 gives you the path of last used/opened (MOST RECENTLY USED- MRU)
you can then use any fm to upload this excel to SAP.
Similar Messages
-
Reading data from an excel file
Hi,
I want to read data from the excel file and display it in
jsp page. Iam getting the following error:
[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con =
DriverManager.getConnection("jdbc:odbc:mydsn","","");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select * from [holidays$]");
Here i have created the dsn with the name "mydsn". I have the
following data in the mydsn.dsn file:
[ODBC]
DRIVER=Microsoft Excel Driver (*.xls)
UID=admin
UserCommitSync=Yes
Threads=3
SafeTransactions=0
ReadOnly=1
PageTimeout=5
MaxScanRows=8
MaxBufferSize=2048
FIL=excel 8.0
DriverId=790
DefaultDir=D:\WorkSpace\Projects\VINET\devl\webroot\jsp
DBQ=D:\WorkSpace\Projects\VINET\devl\webroot\jsp\list_of_holidays_2003.xls
thanks in advance
phani.You might want to look at the POI project (an open source Jakarta sub-project) that allows you to create/modify/read excel files via Java code. That might be more flexible and easier than what you're currently trying to do.
Cheers -
GUI_UPLOAD to read data from an Excel File
Hi Folks,
I'm using FM GUI_UPLOAD to read data from an Excel File. But all I see in the table returned is 1 row with garbage values (special chacaters). Excel Workbook has proper data in the sheet, but its not getting uploaded properly. Sy-subrc is 0.
What could be the reason?
Thanksuse FM : ALSM_EXCEL_TO_INTERNAL_TABLE
See the example program to get from XLS file to Internal table
REPORT ZLWMI151_UPLOAD no standard page heading
line-size 100 line-count 60.
*tables : zbatch_cross_ref.
data : begin of t_text occurs 0,
werks(4) type c,
cmatnr(15) type c,
srlno(12) type n,
matnr(7) type n,
charg(10) type n,
end of t_text.
data: begin of t_zbatch occurs 0,
werks like zbatch_cross_ref-werks,
cmatnr like zbatch_cross_ref-cmatnr,
srlno like zbatch_cross_ref-srlno,
matnr like zbatch_cross_ref-matnr,
charg like zbatch_cross_ref-charg,
end of t_zbatch.
data : g_repid like sy-repid,
g_line like sy-index,
g_line1 like sy-index,
$v_start_col type i value '1',
$v_start_row type i value '2',
$v_end_col type i value '256',
$v_end_row type i value '65536',
gd_currentrow type i.
data: itab like alsmex_tabline occurs 0 with header line.
data : t_final like zbatch_cross_ref occurs 0 with header line.
selection-screen : begin of block blk with frame title text.
parameters : p_file like rlgrap-filename obligatory.
selection-screen : end of block blk.
initialization.
g_repid = sy-repid.
at selection-screen on value-request for p_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = g_repid
IMPORTING
FILE_NAME = p_file.
start-of-selection.
Uploading the data into Internal Table
perform upload_data.
perform modify_table.
top-of-page.
CALL FUNCTION 'Z_HEADER'
EXPORTING
FLEX_TEXT1 =
FLEX_TEXT2 =
FLEX_TEXT3 =
*& Form upload_data
text
FORM upload_data.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
FILENAME = p_file
I_BEGIN_COL = $v_start_col
I_BEGIN_ROW = $v_start_row
I_END_COL = $v_end_col
I_END_ROW = $v_end_row
TABLES
INTERN = itab
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
write:/10 'File '.
ENDIF.
if sy-subrc eq 0.
read table itab index 1.
gd_currentrow = itab-row.
loop at itab.
if itab-row ne gd_currentrow.
append t_text.
clear t_text.
gd_currentrow = itab-row.
endif.
case itab-col.
when '0001'.
t_text-werks = itab-value.
when '0002'.
t_text-cmatnr = itab-value.
when '0003'.
t_text-srlno = itab-value.
when '0004'.
t_text-matnr = itab-value.
when '0005'.
t_text-charg = itab-value.
endcase.
endloop.
endif.
append t_text.
ENDFORM. " upload_data
*& Form modify_table
Modify the table ZBATCH_CROSS_REF
FORM modify_table.
loop at t_text.
t_final-werks = t_text-werks.
t_final-cmatnr = t_text-cmatnr.
t_final-srlno = t_text-srlno.
t_final-matnr = t_text-matnr.
t_final-charg = t_text-charg.
t_final-erdat = sy-datum.
t_final-erzet = sy-uzeit.
t_final-ernam = sy-uname.
t_final-rstat = 'U'.
append t_final.
clear t_final.
endloop.
delete t_final where werks = ''.
describe table t_final lines g_line.
sort t_final by werks cmatnr srlno.
Deleting the Duplicate Records
perform select_data.
describe table t_final lines g_line1.
modify zbatch_cross_ref from table t_final.
if sy-subrc ne 0.
write:/ 'Updation failed'.
else.
Skip 1.
Write:/12 'Updation has been Completed Sucessfully'.
skip 1.
Write:/12 'Records in file ',42 g_line .
write:/12 'Updated records in Table',42 g_line1.
endif.
delete from zbatch_cross_ref where werks = ''.
ENDFORM. " modify_table
*& Form select_data
Deleting the duplicate records
FORM select_data.
select werks
cmatnr
srlno from zbatch_cross_ref
into table t_zbatch for all entries in t_final
where werks = t_final-werks
and cmatnr = t_final-cmatnr
and srlno = t_final-srlno.
sort t_zbatch by werks cmatnr srlno.
loop at t_zbatch.
read table t_final with key werks = t_zbatch-werks
cmatnr = t_zbatch-cmatnr
srlno = t_zbatch-srlno.
if sy-subrc eq 0.
delete table t_final .
endif.
clear: t_zbatch,
t_final.
endloop.
ENDFORM. " select_data -
Excel unable to read WEBI schedule download excel file
Hi experts,
We use BO central management's instance manager to schedule download a report as excel format in our ftp share folder.
And the download did run successfully and an icon of the file been shown as excel format in ftp folder.
while we use excel 2007 to open the file, excel pop out the message of unable to read the file.
it is saying the excel found unreadbale content in report. Do you want to recover the contens of this workbook? if you trust the source of this workbook, click yes. after applied the yes, excel stil pop out the message of unable to read the file.
the general tab in excel been uncheck the "ignore other applications that use Dynamic Data Exchange (DDE), but result still shown unable to read.
The whole set of report can be run in WEBI and using save report to my computer as excel without any issues.
WEBI been setup as refresh on open.
Any clues?Hi,
Did you create a PivotTable report in the file? As your description, the HTML format could be used correctly in Excel 2007. Did you get the other error message?
Such as,Unable to read file.
When you click OK, you receive the following error message:
Errors were detected in '<var>filename</var>.xls', but Microsoft Excel was able to open the file by making the repairs listed below. Save the file to make these repairs permanent.
PivotTable report '<var>report_name</var>' on '[<var>filename</var>.xls]worksheet_name' was discarded due to integrity problems.
Please try to use the workaround:
Turn off AutoRecovery when you work with any workbooks.Click Excel button>Excel options>Save>Uncheck AutoRecovery
Following this, if the issue exists, I recommend you fix the issue the following KB:
http://support.microsoft.com/kb/943088
http://support.microsoft.com/kb/929766
Regards,
George Zhao
TechNet Community Support -
Reading data from multiple excel sheets
hi all
i have to read the data from excel file's sheet1 and sheet3. how can i do this using forms6i
thanks.Dear Rehman,
Use This Code ,it is very useful to read the data from excel file's sheet1 and sheet2 and so on.here i written the code for sheet1 and sheet2 only.if u need sheet3 .. and extra make a code based on sheet1 or sheet2.
Regards
Gopinath M
DECLARE
--Declare handles to OLE objects
application ole2.obj_type;
workbooks ole2.obj_type;
workbook ole2.obj_type;
worksheet ole2.obj_type;
cell ole2.obj_type;
--Declare handles to OLE argument lists
args ole2.list_type;
Check_file text_io.file_type;
no_file exception;
PRAGMA exception_INIT (no_file, -302000);
cell_value varchar2(2000);
BEGIN
--Check the file can be found, if not exception no_file will be raised
Check_file := TEXT_IO.FOPEN('L:\Individual Person Folders\Gopi\test1.XLS','R');
TEXT_IO.FCLOSE(Check_file);
application:= ole2.create_obj('Excel.Application');
workbooks := ole2.get_obj_property(application, 'Workbooks');
--Open the required workbook
args:= ole2.create_arglist;
ole2.add_arg(args, 'L:\Individual Person Folders\Gopi\test1.XLS');
workbook := ole2.invoke_obj(workbooks, 'Open', args);
ole2.destroy_arglist(args);
--Open worksheet Sheet1 of that Workbook
args:= ole2.create_arglist;
ole2.add_arg(args, 'Sheet1');
worksheet := ole2.get_obj_property(workbook, 'Worksheets', args);
ole2.destroy_arglist(args);
--Get value of cell A1 of worksheet Sheet1
args:= ole2.create_arglist;
ole2.add_arg(args, 1);
ole2.add_arg(args, 1);
cell:= ole2.get_obj_property(worksheet, 'Cells', args);
ole2.destroy_arglist(args);
cell_value :=ole2.get_char_property(cell, 'Value');
message(cell_value);
args:= ole2.create_arglist;
ole2.add_arg(args, 1);
ole2.add_arg(args, 2);
cell:= ole2.get_obj_property(worksheet, 'Cells', args);
ole2.destroy_arglist(args);
cell_value :=ole2.get_char_property(cell, 'Value');
message(cell_value);
args:= ole2.create_arglist;
ole2.add_arg(args, 1);
ole2.add_arg(args, 3);
cell:= ole2.get_obj_property(worksheet, 'Cells', args);
ole2.destroy_arglist(args);
cell_value :=ole2.get_char_property(cell, 'Value');
message(cell_value);MESSAGE(' ');
args:= ole2.create_arglist;
ole2.add_arg(args, 'Sheet2');
worksheet := ole2.get_obj_property(workbook, 'Worksheets', args);
ole2.destroy_arglist(args);
--Get value of cell A1 of worksheet Sheet1
args:= ole2.create_arglist;
ole2.add_arg(args, 1);
ole2.add_arg(args, 1);
cell:= ole2.get_obj_property(worksheet, 'Cells', args);
ole2.destroy_arglist(args);
cell_value :=ole2.get_char_property(cell, 'Value');
message(cell_value);
args:= ole2.create_arglist;
ole2.add_arg(args, 1);
ole2.add_arg(args, 2);
cell:= ole2.get_obj_property(worksheet, 'Cells', args);
ole2.destroy_arglist(args);
cell_value :=ole2.get_char_property(cell, 'Value');
message(cell_value);
args:= ole2.create_arglist;
ole2.add_arg(args, 1);
ole2.add_arg(args, 3);
cell:= ole2.get_obj_property(worksheet, 'Cells', args);
ole2.destroy_arglist(args);
cell_value :=ole2.get_char_property(cell, 'Value');
message(cell_value);
MESSAGE(' ');
ole2.invoke(application,'Quit');
--Release the OLE2 object handles
ole2.release_obj(cell);
ole2.release_obj(worksheet);
ole2.release_obj(workbook);
ole2.release_obj(workbooks);
ole2.release_obj(application);
EXCEPTION
WHEN no_file THEN
MESSAGE('file not found.');
WHEN OTHERS THEN
MESSAGE(sqlerrm);
PAUSE;
FOR i IN 1 .. tool_err.nerrors LOOP
MESSAGE(tool_err.message);
PAUSE;
tool_err.pop;
END LOOP;
END; -
CODE - Adding Worksheets to a Workbook in EXCEL .. please help!!
Hi
Does anyone have any code that lets you add multiple worksheets to a workbook in Excel???
I have tried everything!
Help please
ThanksSince you have tried everything I suppose there is no point in referring you to the Apache POI project:
http://jakarta.apache.org/poi/
You've already tried it, right? -
Reading and Writing large Excel file using JExcel API
hi,
I am using JExcelAPI for reading and writing excel file. My problem is when I read file with 10000 records and 95 columns (file size about 14MB), I got out of memory error and application is crashed. Can anyone tell me is there any way that I can read large file using JExcelAPI throug streams or in any other way. Jakarta POI is also showing this behaviour.
Thanks and advanceSorry when out of memory error is occurred no stack trace is printed as application is crashed. But I will quote some lines taken from JProfiler where this problem is occurred:
reader = new FileInputStream(new File(filePath));
workbook = Workbook.getWorkbook(reader);
*sheeet = workbook.getSheet(0);* // here out of memory error is occured
JProfiler tree:
jxl.Workbook.getWorkBook
jxl.read.biff.File
jxl.read.biff.CompoundFile.getStream
jxl.read.biff.CompoundFile.getBigBlockStream Thanks -
Hi all,
I want to read data froma an excel sheet.
The code i used to read the data is
IWDAttributeInfo attributeInfo = wdContext.getNodeInfo().getAttribute(IPrivateFileUplaodView.IContextElement.FILE_RESOURCE);
* IWDModifiableBinaryType binaryType = (IWDModifiableBinaryType) attributeInfo.getModifiableSimpleType();*
* IContextElement element = wdContext.currentContextElement();*
* if(element.getFileResource()!= null)*
* try*
* String mimeType = binary.getMimeType().getFileExtension();*
* wdComponentAPI.getMessageManager().reportSuccess("File " + binaryType.getFileName() + " has been successfuly uploaded ! ");*
* catch(Exception e)*
* throw new WDRuntimeException(e);*
* else*
* wdComponentAPI.getMessageManager().reportException("File could not be uploaded", true);*
* // Till here the code remains the same as in File Upload tutorials*
* // Now the code for retrieving the values from the Excel sheet*
* try*
* ByteArrayInputStream bais = new ByteArrayInputStream(element.getFileResource());*
* Workbook workbook = Workbook.getWorkbook(bais);*
* Sheet sheet = workbook.getSheet(0);*
* Cell a1 = sheet.getCell(0,0);*
* Cell a2 = sheet.getCell(0,1);*
* wdComponentAPI.getMessageManager().reportSuccess("Value of cell a1 = " + a1.getContents());*
* wdComponentAPI.getMessageManager().reportSuccess("Value of cell a2 = " + a2.getContents());*
* catch(Exception ex)*
* wdComponentAPI.getMessageManager().reportException(ex.getLocalizedMessage(),true);*
But i am getting error at "binary" in String mimeType = binary.getMimeType().getFileExtension();
and ByteArrayInputStream bais = new ByteArrayInputStream(element.getFileResource()); by saying that there is no constructor of
ByteArrayInputStream with Resource as parameter.
Please let me know what might be the issue so that i can solve this.
Thanks and regards,
Chandrashekar.Hi,
Replace the following code
ByteArrayInputStream bais = new ByteArrayInputStream(element.getFileResource());*
with
IWDResource resource = element.getFileResource();
InputStream inputStream = resource.read(false);
ByteArrayInputStream bais = new ByteArrayInputStream(inputStream);
Regards
Ayyapparaj -
Script to read data in specific excel sheet
I was wondering whether it was possible to read the data in a specific sheet of a workbook in excel?
I already have one working for reading the file, but was hoping to be able a specific sheet in that file.
With this, is it possible to read the names of the sheets and select the one that you want
Hope you can helpThis should illustrate one way of getting data from different sheets:
<pre style="
font-family: Monaco, 'Courier New', Courier, monospace;
font-size: 10px;
margin: 0px;
padding: 5px;
border: 1px solid #000000;
width: 720px;
color: #000000;
background-color: #FFDDFF;
overflow: auto;">
tell application "Microsoft Excel"
set loopMax to count of worksheets of workbook 1
repeat with sheetNumber from 1 to loopMax
display dialog (value of cell 1 of column 1 of worksheet sheetNumber of workbook 1) as string
end repeat
end tell </pre>
So what I am doing is referencing the sheet by number: e.g. "worksheet 1 of workbook 1" but there are other references you can use such as its name. -
Excel Workbook with Excel Data Model stored on SharePoint - daily refresh
I'm not sure if this is exactly the right forum but I'm hoping that someone here can either answer or point me in the right direction.
I have an Excel Workbook with an Excel Data Model.
The Excel Data Model uses SQL to contact our data warehouse and pull through data into tables.
We are storing the Workbook on a SharePoint site and viewing it using Excel Services.
The data in our data warehouse is updated daily and so I would like to refresh the workbook daily and remove the option to refresh the data in the browser.
Is this possible with a workbook that has an Excel Data Model (I've seen lots of posts that relate to workbooks with connections to tabular models).
Thanks
PaulHi Paul,
I have answered this issue in this thread that you posted in SQL Server PowerPivot for SharePoint forum, please see:
http://social.msdn.microsoft.com/Forums/en-US/9627939c-e9f1-48ae-a6ed-0c238d8f2d69/excel-workbook-with-excel-data-model-stored-on-sharepoint-daily-refresh?forum=sqlkjpowerpointforsharepoint
Furthermore, this issue is more related to PowerPivot for SharePoint. If you have any more questions about PowerPivot for SharePoint, I would sugget you open a new thread in the forum below for better support:
http://social.msdn.microsoft.com/Forums/en-US/home?forum=sqlkjpowerpointforsharepoint
Thanks for your understanding.
Regards,
Elvis Long
TechNet Community Support -
How to read the data in excel sheet
Dear sir,
How to read the data in excel sheet when i recieve a data serial communication... ie i have store a data in excel such that
Cell A Cell B
A Apple
B Ball
C Cat
D Doll
when i recieve A from serial communication i have to display Apple, and when i recieve B i have to display Ball and so on..Hi,
I would recommend you to have a look at the VI attached. It makes use of a VI named 'Read from Spreadsheet' to read the row and column data from the tab delimited excel file. The read data is then searched for the Alphabet specified and finally returns you the corresponding string. The test file used to validate the operation of the VI is also attached.
Trust this would help you solve the issue.
Regards,
Sagar G Yadav | Application Engineer | National Instruments
Attachments:
read_from_excel.vi 10 KB
Book1.txt 1 KB -
How to read the data from Excel file and Store in XML file using java
Hi All,
I got a problem with Excel file.
My problem is how to read the data from Excel file and Store in XML file using java excel api.
For getting the data from Excel file what are all the steps i need to follow to get the correct result.
Any body can send me the code (with java code ,Excel sheet) to this mail id : [email protected]
Thanks & Regards,
Sreenu,
[email protected],
india,If you want someone to do your work, please have the courtesy to provide payment.
http://www.rentacoder.com -
How to read the data from excel file and store into the table?
Hi All,
I have table with BLOB datatype contains a excel file. I have to read that data from excel and store into one table with all the fields in excel.
All the excel fields and my table columns are same.
Can you share with me how can acheive this using LOB's?
ThanksHi OraSuirya,
you can try with external tables .
syntax as follows
create table ext_table_csv (
i Number,
n Varchar2(20),
m Varchar2(20)
organization external (
type oracle_loader
default directory ext_dir
access parameters (
records delimited by newline
fields terminated by ','
missing field values are null
location ('file.csv')
reject limit unlimited;
For this you need to create directory
Directory Creation syntax:
create or replace directory ext_dir as 'D:\oracle\user_dir\ext_dir';
grant read, write on directory ext_dir to <User>;
please paste the excel file in the particular directory .
I hope this will help you.
Please correct me if I am wrong anywhere .
Thanks,
Tippu. -
Reading the data from excel file which is in application server.
Hi,
Iam trying to read the data from excel file which is in application server.
I tried using the function module ALSM_EXCEL_TO_INTERNAL_TABLE. But it didn't work.
I tried just reading using open data set and read data set it is giving junk characters.
Please suggest me if you have any solution.
Best Regards,
Brahma ReddyHi Narendra,
Please see the below code I have written
OPEN DATASET pa_sfile for INPUT in text mode ENCODING DEFAULT MESSAGE wf_mess.
CHECK sy-subrc = 0.
DO.
READ DATASET pa_sfile INTO wf_string.
IF sy-subrc <> 0.
EXIT.
else.
split wf_string at wl_# into wf_field1 wf_field2 wa_upload-field3
wa_upload-field4 wa_upload-field5 wa_upload-field6 wa_upload-field7 wa_upload-field8
wa_upload-field9 wa_upload-field10 wa_upload-field11 wa_upload-field12 wa_upload-field13
wa_upload-field14 wa_upload-field15 wa_upload-field16 wa_upload-field17 wa_upload-field18
wa_upload-field19 wa_upload-field20 wa_upload-field21 wa_upload-field22 wa_upload-field23
wa_upload-field24 wa_upload-field25 wa_upload-field26 wa_upload-field27 wa_upload-field28
wa_upload-field29 wa_upload-field30 wa_upload-field31 wa_upload-field32 wa_upload-field33
wa_upload-field34 wa_upload-field35 wa_upload-field36 .
wa_upload-field1 = wf_field1.
wa_upload-field2 = wf_field2.
append wa_upload to int_upload.
clear wa_upload.
ENDIF.
ENDDO.
CLOSE DATASET pa_sfile.
Please note Iam using ECC5.0 and it is not allowing me to declare wl_# as x as in your code.
Also if Iam using text mode I should use extension encoding etc.( Where as not in your case).
Please suggest me any other way.
Thanks for your help,
Brahma Reddy -
Help! How to read data from an Excel file?
Hi,
I need to read data from an Excel file that may contain more then one table in a sheet. How can I read them?
I would be eternally grateful to anyone who can give me any information.Did you try POI from Apache?
http://jakarta.apache.org/poi/index.html
Maybe you are looking for
-
Time [ Quota Generation for Part-time employees]
Hi Experts, I need a help. I have a following issue. 1] Whenever an employee is marked with a tick '' as Part-time], I want the quota to be generation based on the Weekly workdays [field in SAP WKWDY]. 2] I used the option of defining reduction rul
-
Is there the viber application on Nokia asha 306
I needed to keep in contact with my friends & family. So i checked for viber in the app store & it showed me no result. Please Nokia get a version on Nokia asha 305/306. Moderator's Note: The post was moved to a more appropriate board.
-
Chinese language in need!!!
Got my N73 2 days back and I found out that it does not have chinese language installed in the phone. Does anyone know where to get chinese language or character software to install where i can read my chinese? Thanks
-
Webservice between Web Dispacther and NW
Hi, In the current server architecture, the SAP NW server is sit their local environment or called as DMZ where it is not communicate with the Internet. It have a SAP Web Dispatcher that able to communicate with public. I developed a EJB and expose i
-
Kanban status change trnsactionwise
Dear all, I would like to know, can we control the GR through transactions for kanban production orders? I mean, when i confirm production order through CO15 transaction, i should do confirmation, auto GR (Using control key) and kanban status change