How to read a excel file with more than one worksheet.

Hi,
I wanna read a sheet (anyone of it,not the first) in a excel.Who can help me!
best wishes,
Grant Chen

Dear All,
Thank you all for your reply!
I modified SAP FM ZALSM_EXCEL_TO_INTERNAL_TABLE.
I add an IMPORTING parameter 'I_SHEET' 
which stands for the sequence number of worksheet  in the FM.
FUNCTION ZALSM_EXCEL_TO_INTERNAL_TABLE .
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(FILENAME) LIKE  RLGRAP-FILENAME
*"     REFERENCE(I_SHEET) TYPE  I
*"     VALUE(I_BEGIN_COL) TYPE  I
*"     VALUE(I_BEGIN_ROW) TYPE  I
*"     VALUE(I_END_COL) TYPE  I
*"     VALUE(I_END_ROW) TYPE  I
*"  TABLES
*"      INTERN STRUCTURE  ALSMEX_TABLINE
*"  EXCEPTIONS
*"      INCONSISTENT_PARAMETERS
*"      UPLOAD_OLE
*{   INSERT         EC6K900099                                        1
  DATA: excel_tab     TYPE  ty_t_sender.
  DATA: ld_separator  TYPE  c.
  DATA: application   TYPE  ole2_object,
        workbook      TYPE  ole2_object,
        range         TYPE  ole2_object,
        worksheet     TYPE  ole2_object.
  DATA: h_cell        TYPE  ole2_object,
        h_cell1       TYPE  ole2_object.
  DATA:
    ld_rc             TYPE i.
*   Rückgabewert der Methode "clipboard_export     "
* Makro für Fehlerbehandlung der Methods
  DEFINE m_message.
    case sy-subrc.
      when 0.
      when 1.
        message id sy-msgid type sy-msgty number sy-msgno
                with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      when others. raise upload_ole.
    endcase.
  END-OF-DEFINITION.
* check parameters
  IF i_begin_row > i_end_row. RAISE inconsistent_parameters. ENDIF.
  IF i_begin_col > i_end_col. RAISE inconsistent_parameters. ENDIF.
* Get TAB-sign for separation of fields
  CLASS cl_abap_char_utilities DEFINITION LOAD.
  ld_separator = cl_abap_char_utilities=>horizontal_tab.
* open file in Excel
  IF application-header = space OR application-handle = -1.
    CREATE OBJECT application 'Excel.Application'.
    m_message.
  ENDIF.
  CALL METHOD  OF application    'Workbooks' = workbook.
  m_message.
  CALL METHOD  OF workbook 'Open'    EXPORTING #1 = filename.
  m_message.
*  set property of application 'Visible' = 1.
*  m_message.
********************Modified by Grant 20080717************
  call METHOD of application 'Worksheets' = worksheet
  exporting
    #1 = I_SHEET.
  m_message.
  call method of worksheet 'Activate'.
*  GET PROPERTY OF  application 'ACTIVESHEET' = worksheet.
  m_message.
* mark whole spread sheet
  CALL METHOD OF worksheet 'Cells' = h_cell
      EXPORTING #1 = i_begin_row #2 = i_begin_col.
  m_message.
  CALL METHOD OF worksheet 'Cells' = h_cell1
      EXPORTING #1 = i_end_row #2 = i_end_col.
  m_message.
  CALL METHOD  OF worksheet 'RANGE' = range
                 EXPORTING #1 = h_cell #2 = h_cell1.
  m_message.
  CALL METHOD OF range 'SELECT'.
  m_message.
* copy marked area (whole spread sheet) into Clippboard
  CALL METHOD OF range 'COPY'.
  m_message.
* read clipboard into ABAP
  CALL METHOD cl_gui_frontend_services=>clipboard_import
    IMPORTING
      data                 = excel_tab
    EXCEPTIONS
      cntl_error           = 1
*      ERROR_NO_GUI         = 2
*      NOT_SUPPORTED_BY_GUI = 3
      OTHERS               = 4
  IF sy-subrc <> 0.
     MESSAGE a037(alsmex).
  ENDIF.
  PERFORM separated_to_intern_convert TABLES excel_tab intern
                                      USING  ld_separator.
* clear clipboard
  REFRESH excel_tab.
  CALL METHOD cl_gui_frontend_services=>clipboard_export
     IMPORTING
        data                 = excel_tab
     CHANGING
        rc                   = ld_rc
     EXCEPTIONS
        cntl_error           = 1
*       ERROR_NO_GUI         = 2
*       NOT_SUPPORTED_BY_GUI = 3
        OTHERS               = 4
* quit Excel and free ABAP Object - unfortunately, this does not kill
* the Excel process
  CALL METHOD OF application 'QUIT'.
  m_message.
* >>>>> Begin of change note 575877
* to kill the Excel process it's necessary to free all used objects
  FREE OBJECT h_cell.       m_message.
  FREE OBJECT h_cell1.      m_message.
  FREE OBJECT range.        m_message.
  FREE OBJECT worksheet.    m_message.
  FREE OBJECT workbook.     m_message.
  FREE OBJECT application.  m_message.
* <<<<< End of change note 575877
*}   INSERT
ENDFUNCTION.
Edited by: Grant Chen on Jul 17, 2008 7:45 AM
Edited by: Grant Chen on Jul 17, 2008 7:46 AM

Similar Messages

  • How to read an internal table with more than  one (2 or 3) key field(s).

    how to read an internal table with more than  one (2 or 3) key field(s). in ecc 6.0 version

    hi ,
    check this..
    report.
    tables: marc,mard.
    data: begin of itab occurs 0,
          matnr like marc-matnr,
          werks like marc-werks,
          pstat like marc-pstat,
          end of itab.
    data: begin of itab1 occurs 0,
          matnr like mard-matnr,
          werks like mard-werks,
          lgort like mard-lgort,
          end of itab1.
    parameters:p_matnr like marc-matnr.
    select matnr
           werks
           pstat
           from marc
           into table itab
           where matnr = p_matnr.
    sort itab by matnr werks.
    select matnr
           werks
           lgort
           from mard
           into table itab1
           for all entries in itab
           where matnr = itab-matnr
           and werks = itab-werks.
    sort itab1 by matnr werks.
    loop at itab.
    read table itab1 with key matnr = itab-matnr
                              werks = itab-werks.
    endloop.
    regards,
    venkat.

  • How can I search for files with more than one keyword?

    I´ve created some keywords, and some files in my folder are tagged with two, three or more keywords.
    Is there a way to search for files using more than one keyword on the search field?
    Thanks!

    Use the Find command (menu Edit) and in criteria at the right side is a plus sign to add another criteria and set it to your custom wishes.
    make a choice in results and you should be OK

  • How do I merge multiple Excel files with more than one tab in each file using PowerQuery?

    Hello
    I have 12 Excel (.xlsx) files and each file has three identically named and ordered tabs in them. 
    I know how to merge multiple Excel files in a folder using M (those guides are all over the web) but how do I merge multiple Excel files with multiple (yet identically named and ordered) tabs? Surely it is possible? I just don't know how to do it in M.
    Cheers
    James

    What Laurence says is correct, and probably the best thing to do when the sheets have differing structures. Here is an alternate approach that works well when the sheets all have the same structure.
    When you first open the Excel file from Power Query, you can see its structure in the navigator at the right-hand-side of the screen. If you select the root (which is the filename itself) and click Edit, you'll see all the tabs in the sheet as a single table.
    You can now do filtering based on the Name, Item and Kind values. When you've reduced the set of things down to the sheets you want, select the Data column and say "Remove Other Columns". If the sheets don't have any header rows, you can just click the expand
    icon in the header and you'll be done.
    Otherwise, if the sheets have headers or if some other kind of sheet-level transformation is required against each sheet before doing a merge, you'll have to write some M code manually. In the following example, each sheet has a header row consisting of
    two columns: Foo and Bar. So the only step I need to perform before merging is to promote the first row into a header. This is done via the Table.TransformColumns operation.
    let
        Source = Excel.Workbook(File.Contents("C:\Users\CurtH\Desktop\Test1.xlsx")),
        RemovedOtherColumns = Table.SelectColumns(Source,{"Data"}),
        PromotedHeaders = Table.TransformColumns(RemovedOtherColumns,{{"Data", each Table.PromoteHeaders(_)}}),
        ExpandData = Table.ExpandTableColumn(PromotedHeaders, "Data", {"Foo", "Bar"}, {"Data.Foo", "Data.Bar"})
    in
        ExpandData

  • How can i use my iphone with more than one itunes

    how can i use my iphone with more than one itunes

    Sync iPod/iPad/iPhone with two computers
    Although it isn't possible to sync an Apple device with two different libraries it is possible to sync with the same logical library from multiple computers. Each library has an internal ID and when iTunes connects to your iPod/iPad/iPhone it compares the local ID with the one the device normally syncs with. If they are the same you can go ahead and sync...
    I have my library cloned to a small 1Tb USB drive which I can take between home & work. At either location I use SyncToy 2.1 to update the local copy with the external drive. Mac users should be able to find similar tools. I can open either of the local libraries or the one on the external drive and update the media content of my iPhone. The slight exception is Photos which normally connects to a specific folder on a specific machine, although that can easily be remapped to the current library if you create a "Photos" folder inside the iTunes Media folder so that syncing the iTunes folders keeps this up to date as well. I periodically sweep my library for new files & orphans with iTunes Folder Watch just in case I make changes at one location but then overwrite the library with a newer copy from the other. Again Mac users should be able to find similar tools.
    As long as your media is organised within an iTunes Music or Tunes Media folder, in turn held inside the main iTunes folder that has your library files (whether or not you let iTunes keep the media folder organised) each library can access items at the same relative path from the library folder so the library can be at different drives/paths on different machines. This solution ensures I always have adequate backups of my library and I can update my devices whenever I can connect to the same build of iTunes.
    When working with an iPhone earlier builds of iTunes would remove any file not physically present in the local library, even if there was an entry for it, making manual management practically redundant on the iPhone. This behaviour has been changed but it will still only permit manual management with a library that has the correct internal ID. If you don't want to sync your library between machines on a regular basis just copy the iTunes Library.itl file from the current "home" machine to any other you want to use, then clean out the library entries and import the local content you have on that box.
    tt2

  • How do I share my contacts with more than one group? I really don't want to have re-type them into a different group. Help!

    How do I share my contacts with more than one group without having to re-type them into each group?

    Without "pretending" to be yourself on the other phone (change settings) there's nothing else you can do.
    iOS devices are meant to be single user and can't view iCloud.com the same way a Mac or PC can do.
    You need to find a desktop or laptop machine (Mac or PC) to log in at iCloud.

  • How to generate a certificate request with more than one OU?

    We're using Sun Java System Web Server 6.1 SP4. The Corp. has it's own CA and organize their certificates in a hierarchical rule with more then one organization unit (OU) in a chain.
    So what we need is generate a certificate requeste with more than one OU, but the Web Server wizard has only one text field for it. We've already tried to fill in this field the complete chain of OUs like "ou=orgX, ou=deptY, ou=secZ" and didn't work either.
    Thank's in advance,
    Jeff!

    Do you have tried with the command line "certutil" ?
    #<SERVER-ROOT>/bin/https/admin/bin/certutil

  • Creating Interactive Files with more than one URL

    Hello, here's my problem: I want to create more than one button instance that go to different URL address's. From the Adobe Video Workshop, I got the code:
    interactive_test.addEventListener(MouseEvent.CLICK, buttonClickHandler);
    function buttonClickHandler(event:MouseEvent):void {
                    navigateToURL(new URLRequest("http://www.adobe.com"));
    This works fine with one button instance. When I copy and paste the code for another button instance, i.e:
    butn1.addEventListener(MouseEvent.CLICK, buttonClickHandler);
    function buttonClickHandler(event:MouseEvent):void {
                    navigateToURL(new URLRequest("http://www.adobe.com"));
    butn2.addEventListener(MouseEvent.CLICK, buttonClickHandler);
    function buttonClickHandler(event:MouseEvent):void {
                    navigateToURL(new URLRequest("http://www.adobe.com"));
    I get 1021 duplicate function error. I think I understand in priciple what's wrong but don't know how to fix it. MyI knowledge of Action Script 3 is zero. What I need is sample code that works that I could copy and paste, with appropriate changes.
    Thanks in advance for your help, Richard

    use different function names or flash won't know which function to use:
    butn1.addEventListener(MouseEvent.CLICK, buttonClickHandler1);
    function buttonClickHandler1(event:MouseEvent):void {
                    navigateToURL(new URLRequest("http://www.adobe.com"));
    butn2.addEventListener(MouseEvent.CLICK, buttonClickHandler2);
    function buttonClickHandler2(event:MouseEvent):void {
                    navigateToURL(new URLRequest("http://www.adobe.com"));

  • Can not import excel spreadsheet with more than one spreadsheet from an email

    i get excel files sent to me all the time by email and have been able to open most of them.  Went to a apple store and was told i needed to install numbers app on my iphone 4 to open them up because their was more than likely two or more work sheets in that file. i am on the road and can't get to my imac.  I bought numbers did all the updates on the iphone and sync to itunes.  it still cant open the spreadsheets if they have more than one work sheet. it does ask do you want to open in numbers i answer the question it starts the import then get error message spreadsheet couldn't be imported.  the file format is invalid.
    this is frustrating to by an app that was suggested by apple for the solution and it doesn't work.
    by the way i have excel on the macbook pro and imac so that is not an issue need to be able to see on the phone while traveling.
    by the way it says microsoft excel 97-2004 worksheet 16 kb open in "numbers"
    Any suggestions

    Hi Caroline
    you should be able to apply the exact same principles to your multi query report. The XML will have a main root node and then the results of the queries underneath.
    So if you had 3 queries you'd get something like
    <REPORTNAME>
    <G_FIRST_QUERY>
    </G_FIRST_QUERY>
    <G_SECOND_QUERY>
    <G_SECOND_QUERY>
    <G_THIRD_QUERY>
    <G_THIRD_QUERY>
    </REPORTNAME>
    In the template you will be able to map on to the separate sections of the XML very easily.
    regards, Tim

  • How to read an excel file with unknown fields

    Hi,
    I am trying to import data from an Excel file through java.. [Netbeans as the IDE] I got this sample running code online [http://rgagnon.com/javadetails/java-0362.html] which was very helpful.. but i want to read from an excel file even if i dont know the fields in it.. Is this possible somehow?

    Google "POI HSSF" and or "Andy Khan jxl"
    Edit: If you insist on using the bridge, then take a look at the DatabaseMetaData class, or do a select * and look at the ResultSetMetaData class, although you are much better off not trying to use a Spreadsheet as a database, it isn't one, after all.

  • How to extract data into excel file from more than one internal table

    Hi Guys
                 I want to extract the data from module pool screen.
                 In screen there are two internal tables
                      1. header
                      2. items.
                 I want to extract the data as same format looking in the screen.
                 With simple Download FM we cannot do this one, because in this we   will display as continuous rows.
    <b> But my requirement is saving as table with heading, date, header details</b>
    Note that it is not the simple down load . Suggest me with example  coding

    Hi Guys,
      I think it depends on which software you will use to see the result.
      If U are using Excel, it's very easy to achieve it.
      1. Define a structure as string, the lenth depend on your need.And use the structure to define a internal table, supposed is as A..
      2. Concatenate the head data using some separator, for ex. a comma; and then add this into A.
      3. The above step's concatenate is depend on your format for request;For ex, you want to place the date at the 4th cell in excel, that means you should put three separator before the date field.
      4 Concatenate the item data into the download table.
      5. Download the table to file.
      6. Display the file, using your defined separator.
    Hope this helpful.
    Bob

  • How to use "URLConnection" in sessions with more than one screen??

    Hi,
    Requests can be sent to http servers using "URLConnection" objects. The responses can be parsed via their InputStream; so far so good...
    Question is:
    What can I do when I want to send a request to a server where there is first a log-in screen and only then there is the desired screen where the real request should be sent?
    Since the REAL request cannot be directly sent without the authentication check first, I need some kind of "context" or session in which I may make some consequent actions... Sending an independent request using a diferent URLConnection just won't do since I'm unauthorized via the second connection!!
    Generally, I need a way to send consequent requests where the second request may be sent only if the first request authenticated me...
    How can I do that? (Hope my question is clear...)
    --Amir.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Well, you will have to deal with the cookies or however the server knows you are authenticated. Personally I prefer to use something like Apache HttpClient rather than dealing with icky details like that on my own.

  • File with more than one texture

    Hello, I'm having a problem with an animation I am working on. I have a file that contains three sprites on one sheet. What I ususally do it load the sheet onto the stage, then I try and erase the two extra sprites until I need them. Everytime I try it just erases the black background on the previous layer. I've tried switching back to the layer the sprite was on and erasing; but, It still switches to the black background layer and erasies that. I have the sprite sheet in a psd file and I still can't edit it while within the program.

    It is not clear what you mean when you talk about sheets (?) and erasing things - why not just have separate sheets for each ? 
    If you have layers involved and things are on separate layers, then you should be able to lock any layer you do not want to affect.  So you should be able to lock the black background layer and any others except the one you wish to erase.

  • How to find all generated profiles (with more than one nomenclature)

    Hello all,
    I have an Solution Manager 4.0 system and I want to find out:
    a. all sap profiles created via SU02 (not generated profiles)
    b. all generated profiles
    b. all generated profiles with user assignment
    Initially I extracted values from tables UST10C and UST10S for single and comp. profile information. For profile assignment, I searched UST04. But then I realized that generated profiles don't follow a standard nomenclature. Some start with T-54, some with T-56, then T-AA, T-MW [now there some T_MW profiles created via SU02 ]
    Can anyone help me here please?
    Thanks and regards,
    Sundar.

    Hi Sundar,
    please check table USR10.
    The interesting field for you is USR10-Typ.
    Field value meanings:
    C    Composite Profile 
    G    Generated Profile 
    S    Single profile   
    b.rgds, Bernhard

  • Post document to content library with more than one tab

    Hi
    In BPC 7.0 I have been trying to post an html file (converted from an excel file with several tabs) to the content library, but when previewing or trying to open the document it shows "The page cannot be found... HTTP error 404 - File or directory not found."
    Saving other files with just one tab or word documents is no problem.
    Thanks for any advice.
    Regards
    Melanie

    Hi Ulrike,
    If the problem only comes from Excel files having more than one tab, you should raise this to support, as it could represent a potential bug.
    When opening your message, do not forget to provide:
    - BPC version and Service pack
    - SQL server version and service pack and Cumulative update
    - Multi or single environment
    - Try to reproduce the same problem into ApShell, and attach a step-by-step document to the ticket. Support will always ask you for that.
    Kind Regards,
    Patrick

Maybe you are looking for

  • Bug in iPhone 2.0.2 maps app.

    I have run into this on several occasions. Tap Maps. Do a search (ex Pizza) Select one of the results... Tap "Directions to here" Now, here is where I have had issues. If your Start point is not "Current location", which happens if you're rerouting i

  • Upgraded computer and PSE... where are old tags?

    I recently got a new computer. I also changed OS from Windows 7 32bit to Windows 7 64bit which required re-formating my drive. I made a backup copy of everything. After installing the new OS, I upgranded from PSE 8 to PSE 9. I tried importing my pict

  • I'm not able to get my mac os 10.6.8 to print to a Savin C2525, any suggestions?

    I'm not able to get my Mac OS 10.6.8 to print to a Savin C2525. I've loaded the drivers and after checking for updates and tried to add the printer. The 1st time I tried, it started printing and I could see the file name on the first page, after it p

  • HELP!!! Error "code too large"

    Hello, I am working on a program that has become very large... and apparently it is too large now... When I try to compile the program it generates an error, "code too large", the code has exceeded 10000 lines and now I dont know what to do. Anyone t

  • Filter Extractor with POF

    I am in the process of converting serialized beans to pof. Most of the stuff working except wherever ValueExtractor used in filter. This is the exception i m seeing on server as well as on client. BTW, we are using TCP extend for setting up client-se