WD ABAP - Worksheet issue of Excel sheet

Hi experts,
The requirement is such that there is a link and a table.
When the link will be clicked the whole table will be downloaded into excel file.
I have written a code to download the table into excel file.
Here is the part of the code----
convert 'Text' to 'XTEXT'
    CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
      EXPORTING
        text   = l_text1
      IMPORTING
        buffer = l_xtext1.
    wdr_task=>client_window->client->attach_file_to_response(
*path to the word file
       i_filename = l_filename
String Variable
      i_content =  l_xtext1
File Type
      i_mime_type = 'EXCEL').
When the link is being clicked a pop up comes with three options 'Open','Save' and 'Cancel'.
If 'Save' is clicked the file is name with a name 'Reportee.xls' and when the excel sheet is being opened in the worksheet ,it shows the name 'Reportee.xls'.
Issues----
The issue arises when user clicks 'Open' option and worksheet area it shows '.xls]Repotee(1)'.
Instead of '.xls]Repotee(1)' it should be 'Reportee.xls'.
Please help me sort out the issue.
Thanking you.
Anindita Banerjee

Hi Anandita,
Try using the Variable "File Type" in the method call attach_file_to_response.
Cheers,
Kunjal

Similar Messages

  • A temporary solution for issue of excel sheet for SO_NEW_DOCUMENT_ATT_SEND_

    Hi,
    we all sometime or the other have faced the problem with SO_NEW_DOCUMENT_ATT_SEND_API1, it passes all the data into a single excel sheet. the following is the code i have written using the same standard FM to resolve the issue.
    Problem's Facing     : To send the output of a report as mail attachment (Excel sheet) from SAP, to the User's outlook or TCP/IP
    What is happening     : All the data which is being passed to the excel is being put in a single cell of the excel sheet.
    Cause               : the difficulty lies in getting the internal table from SAP report, passing it to email Function Module If the structure of the internal Table is unknown .
    Solution:
    if the user while sending data to the Function module ( created using the following code) puts a '#' between field values, all the fields gets separated into individual cells and the data gets printed as required.
    <b>advantages</b> of the following code are:
    1) User just need to type userid or multiple userid's separated by comma.
    2) Performs multiple tasks with one function module.
    3) It can be used to send file with subject only
    4) It can be used to send file with subject and body
    5) It can be used to send file with subject, body, and attachment
    6) Attachment can be of 'TXT' format or 'XLS' format depending upon the choice of the user.
    7) User specific parameters for EMAILID, subject, body and attachment type avoiding the dump error of  "Type conflict"
    8) If the user requires to send output of a report as an excel file, then a single internal table will store the total output separating the field values by ' # ' and the data gets printed evenly. the ' # '  symbol is used as Tab delimiter.
    FUNCTION zemail_attachment.
    ""Local Interface:
    *"  IMPORTING
    *"     REFERENCE(EMAILID)
    *"     REFERENCE(SUBJECT)
    *"     REFERENCE(ATYPE)
    *"  TABLES
    *"      ATTACH_FILE STRUCTURE  SOLISTI1
    *"      BODY OPTIONAL
    *"  EXCEPTIONS
    *"      INCORRECT_PARAMETERS
    This table requires information about how the data in the
    tables OBJECT_HEADER, CONTENTS_BIN and CONTENTS_TXT are
    to be distributed to the documents and its attachments.
      DATA it_objpack LIKE sopcklsti1 OCCURS  2 WITH HEADER LINE.
    This table must contain the summarized data dependent on each object type.
    SAPscript objects store information here about forms and styles,
    for example. Excel list viewer objects store the number of rows and columns
    amongst other things and PC objects store their original file name.
      DATA it_objhead LIKE solisti1   OCCURS  1 WITH HEADER LINE.
    This table must contain the summarized content of the objects identified as binary objects.
      DATA   it_objbin TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
                     WITH HEADER LINE.
    This table must contain the summarized content of the objects identified as ASCII objects.
      DATA it_objtxt  LIKE solisti1   OCCURS 10 WITH HEADER LINE.
    This table must contain the document recipients.
      DATA  it_reclist LIKE somlreci1 OCCURS 5 WITH HEADER LINE .
    This structure must contain the attributes of the document to be sent.
      DATA: doc_ching LIKE sodocchgi1.
      DATA: tab_lines LIKE sy-tabix.
    Create the internal table for body , subject
      DATA: it_body LIKE solisti1 OCCURS 10 WITH HEADER LINE.
    *creation of internal table for Email-id.
      DATA: BEGIN OF it_mailid OCCURS 0,
            email LIKE kna1-name1 ,
            END OF it_mailid.
    *VARIABLES
      DATA : v_hash(1) TYPE c VALUE '#'.
      DATA: v_string1 LIKE kna1-name1,
            v_string2 LIKE kna1-name1,
            v_string3(12) TYPE c VALUE '@GMAIL.COM'.
    *CONSATNTS
      CONSTANTS: c_con_cret TYPE c VALUE cl_abap_char_utilities=>horizontal_tab,
                 c_con_tab  TYPE c VALUE cl_abap_char_utilities=>cr_lf,
                 c_raw(3)   TYPE c VALUE 'RAW',
                 c_comma(1) TYPE c VALUE ',',
                 c_rec_type(1) TYPE c VALUE 'U',
                 c_space(1)    TYPE c VALUE ''.
    Move Body to Internal Table (body into it_body)
      LOOP AT body .
        MOVE body TO it_body .
        APPEND it_body .
      ENDLOOP.
      doc_ching-obj_descr = subject.   "Subject of the Email
    Move the Subject and Body to OBJTXT
      it_objtxt[] = it_body[].
      DESCRIBE TABLE it_objtxt LINES tab_lines.
      READ TABLE it_objtxt INDEX tab_lines.
      doc_ching-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( it_objtxt ).
      CLEAR it_objpack-transf_bin.
    it_objpack-head_start = 1.
    it_objpack-head_num   = 0.
    it_objpack-body_start = 1.
    it_objpack-body_num   = tab_lines.
    it_objpack-doc_type   = c_raw.
      APPEND it_objpack.
    Convert to Excel format
    IF NOT attach_file[] IS INITIAL.
      IF atype IS INITIAL.
    RAISE INCORRECT_PARAMETERS.
      ELSEIF atype = 'XLS' .
        LOOP AT attach_file .
          CONCATENATE attach_file v_hash INTO attach_file.
          REPLACE ALL OCCURRENCES OF v_hash IN attach_file WITH c_con_cret.
          IF sy-tabix = 1.
            MOVE attach_file TO it_objbin.
          ELSE.
            CONCATENATE c_con_tab attach_file INTO it_objbin.
          ENDIF.
          APPEND  it_objbin.
        ENDLOOP.
      ELSEIF atype = 'TXT' .
    Convert to Text format
        LOOP AT attach_file .
          REPLACE ALL OCCURRENCES OF v_hash IN attach_file WITH c_con_cret.
          CONCATENATE attach_file c_con_tab  INTO it_objbin .
          APPEND it_objbin .
        ENDLOOP.
      ENDIF.
      DESCRIBE TABLE it_objbin LINES tab_lines.
      it_objhead = subject. APPEND it_objhead.
    Creating the entry for the compressed attachment
      it_objpack-transf_bin = 'X'.
      it_objpack-head_start = 1.
      it_objpack-head_num   = 1.
      it_objpack-body_start = 1.
      it_objpack-body_num   = tab_lines.
    *check for XLS ,TXT files
      IF atype = 'XLS'.
        it_objpack-doc_type   = atype.
      ELSEIF atype = 'TXT'.
        it_objpack-doc_type   = c_raw.
      ENDIF.
      it_objpack-obj_name   = 'ATTACHMENT'.
      it_objpack-obj_descr = 'ATTACHMENT'. "Attachment File Name
      it_objpack-doc_size   = tab_lines * 255.
      APPEND it_objpack..
    ENDIF.
    Entering names in the distribution list
    Concatenating the email with '@GMAIL.COM if the user doesnot specify any mail extension
    recipent type as U - for internet usage
      SPLIT emailid AT c_comma INTO TABLE it_mailid.
      APPEND it_mailid.
      LOOP AT it_mailid.
        SHIFT it_mailid-email LEFT DELETING LEADING c_space.
        SPLIT it_mailid-email AT '@' INTO: v_string1 v_string2.
        IF v_string2 IS INITIAL AND NOT it_mailid-email IS INITIAL.
          CONCATENATE v_string1 v_string3 INTO it_reclist-receiver.
          it_reclist-rec_type = c_rec_type.
          APPEND it_reclist.
          CLEAR: v_string1,v_string2.
        ELSE.
          it_reclist-receiver = it_mailid-email.
          it_reclist-rec_type = c_rec_type.
          APPEND it_reclist.
        ENDIF.
      ENDLOOP.
      CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
        EXPORTING
          document_data              = doc_ching
          put_in_outbox              = 'X'
          commit_work                = 'X'
        TABLES
          packing_list               = it_objpack
          object_header              = it_objhead
          contents_bin               = it_objbin
          contents_txt               = it_objtxt
          receivers                  = it_reclist
        EXCEPTIONS
          too_many_receivers         = 1
          document_not_sent          = 2
          operation_no_authorization = 4
          OTHERS                     = 99.
    ENDFUNCTION.
    If anyone, has a better solution, please share
    Cheers
    Ajay

    issue resolved

  • ALV layout issue in excel sheet

    Hi all,
    When i executed my report, it will send the output  data in excel format to my email id.
    It is  ALV report. When i changed the layout , the layout change is happening in report output, but in my excel sheet chagned layout set was not coming. It is coming old format only.
    Is there any FM to handle the dynamic  layouts
    please help me in this.
    regards,
    Ajay Ram

    Hi Ajay
    When you change the layout, its done in the ALV o/p or rather in foreground.
    You can't make this layout change be reflected in the excel sheet that is made thru background job.
    One option is to save the layout you want and then before executing the ALV report, load the layout you want by using FMs
    REUSE_ALV_VARIANT_DEFAULT_GET
    REUSE_ALV_VARIANT_F4
    REUSE_ALV_VARIANT_EXISTENCE
    You can get the sample codes in sdn by searching for these FMs
    Reward points if useful
    Cheers
    ~Arun

  • E61: Compatibility issue with Excel sheets

    Hello,
    I am having difficulties transferring an Excel file from my E61 to my laptop running Office 2007: I had originally written
    the file in Office 2003 and I have now added two more sheets to the file and renamed the original sheet on my E61. When I tried transferring the file via the
    data cable, I got a message saying unreadable contents were found in the file and asking me if I trusted the source. When I clicked OK, the file
    was repaired, then I got a second message saying there might possibly be some data loss. Indeed, all the data was gone from
    the Workbook. All the sheets I had added were there along with the one sheet that was there originally, but they were all blank. The **bleep** thing about this is that I had already transferred the file back and forth a few times without error.
    I then tried with another Excel file that I had originally written on a PC running Office 2007 and it was nearly the same. In that file, all the data seemed
    to be there, but the formatting was gone. In yet another file that I had written on the mobile, it was even worse - the numeric values that I had entered in
    some cells seemed to be there, but incorrectly formatted while text cells were altogether gone.
    Can anybody tell me what I did wrong there?
    Thanks a lot!
    Regards,
    Hendikoischnur
    P.S.: The same thing happened when I didn´t transfer the file to the laptop at all, but left the phone connected via cable
    and tried to open the file from the memory card in Data transfer mode. Opening the file on the mobile itself, however, was no problem.
    P.P.S.: This is really rather important - one of the files in question is a collection of all my personal passwords. Out of security
    considerations, I´m thinking of having that file only on my mobile, copy it to the PC at need
    and shred that copy afterwards, so it would be quite fatal if
    I wasn´t able to transfer the file back to my Desktop or even open it in Data transfer mode.
    IT will paint our future - either green or black
    * ecosia, the eco-friendly search engine (powered by Yahoo/Bing/WWF);
    * Searching for pics online? Try ecocho.eu or treehoo.com
    * For those who don´t want to miss Google: Try znout.de - it´s Google running on green energy
    * CO2-free chatting: Try Jabber-server.de (running on 100% waterpower)

    Hi,
    does nobody have an idea about this? I have already contacted the Nokia Support, but the guy there asked me a lot of questions apt for complete computer-newbies without bringing me any nearer to a solution. I already thought that maybe my memory card is damaged - but then, the phone shouldn´t display the contents flawlessly.
    Next I will try if maybe the problem is only with Office 2007 and I can open the files with Office XP or maybe with CALC, although that would be somewhat weird...
    Regards,
    Hendikoischnur
    IT will paint our future - either green or black
    * ecosia, the eco-friendly search engine (powered by Yahoo/Bing/WWF);
    * Searching for pics online? Try ecocho.eu or treehoo.com
    * For those who don´t want to miss Google: Try znout.de - it´s Google running on green energy
    * CO2-free chatting: Try Jabber-server.de (running on 100% waterpower)

  • Convert into Data Table issue from Excel Sheet Table

    Hi 
    i've excel file where 10-12 sheets are available in that excel file.one of the sheet is named as summary.there are 8-10 tables(named as Table1,Table2,Table3....) in that summary sheet as well. 
    i've to actually get the Table1 from the summary sheet into the DataTable. 
    So,i've written a following method to read "summary" sheet and then i checked if the Table1 exist then break the loop.My problem is i've found Table1 but i am not able to convert it into the DataTable.Can anyone tell me how to do it.
    private void GetProjectTable(string ExcelFileUrl)
    string sheetName = "Summary";
    string value = null;
    // Open the spreadsheet document for read-only access.
    try
    String siteURL = SPContext.Current.Site.Url;
    SPSecurity.RunWithElevatedPrivileges(delegate()
    Stream dataStream = null;
    using (SPSite site = new SPSite(siteURL))
    using (SPWeb web = site.OpenWeb())
    SPFile file = web.GetFile(ExcelFileUrl);
    dataStream = file.OpenBinaryStream();
    using (SpreadsheetDocument document =
    SpreadsheetDocument.Open(dataStream, false))
    // Retrieve a reference to the workbook part.
    WorkbookPart wbPart = document.WorkbookPart;
    Sheet theSheet = wbPart.Workbook.Descendants<Sheet>().
    Where(s => s.Name == sheetName).FirstOrDefault();
    // Throw an exception if there is no sheet.
    if (theSheet == null)
    throw new ArgumentException("sheetName");
    WorksheetPart wsPart =
    (WorksheetPart)(wbPart.GetPartById(theSheet.Id));
    DocumentFormat.OpenXml.Spreadsheet.Table table = null;
    DataTable dt = null;
    foreach (TableDefinitionPart tdp in wsPart.TableDefinitionParts)
    if (tdp.Table.DisplayName == "Table1")
    table = tdp.Table;
    break;
    catch (Exception ex)
    Note: I am using this code in the Visual Web Part for SharePoint

    Hi hellofragrance,
    According to the description, you want to convert to the table in Excel to DataTable using Open XML SDK.
    As far as I know, there is no such API we can achieve the goal directly. However, we can write custom code to complete the job. Here are some major steps for your reference:
    1. Get the information of the table we wanted to convert. For example, column information and the range address for the table. And we can get the these information via the
    Table object of
    TableDefinitionPart Class
    2. Then we can create a DataTable via the column information we get from step1 and initialize the data table via read the data from range of table.
    In addition, here is helpful article about read the value of specific cell for your reference:
    How to: Retrieve the values of cells in a spreadsheet document (Open XML SDK)
    Regards & Fei
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • LINK Excel.Sheet has issues with Non-English Office

    In non-english office when we issue
    LINK  Excel.Sheet.12 command, the range parameter is causing "Error! Invalid Link" error (¡Error! Vínculo no válido in spanish).
    Example if we do:
    {LINK  Excel.Sheet.12 C:\\Temp\\Text.xlsx  Test!R1C1:R2C2 \a \f 4 \h}
    We get invalid link error (in spanish).
    But when we remove the range parameter:
    {LINK  Excel.Sheet.12 C:\\Temp\\Text.xlsx  \a \f 4 \h}
    It works. This of course by default links only the first sheet by default. Anyone knows if this is a bug in Office for non-english? We are using Office 2010.

    Hi V.C.A,
    Based on your description, it seems that your issue was related with the field link feature of the Word, and this forum is mainly discussing about the Word development questions related to VSTO, VBA and .etc. For your issue, I will recommend you going to
    the forum below for help:
    http://answers.microsoft.com/en-us/office​
    Thanks for your understanding.
    Best Regards,
    Edward
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

  • Download the ALV Report output into excel sheet or notepad

    Hi,
    how to downlaod the alv report out into excel sheet or notepad in a proper manner. program contain large number records....
    Thanks in advance!!!!
    Regards,
    kranthi.

    Hi
    Download a report to excel with format (border, color cell, etc) 
    Try this program...it may help you to change the font ..etc.
    Code:
    REPORT ZSIRI NO STANDARD PAGE HEADING.
    this report demonstrates how to send some ABAP data to an
    EXCEL sheet using OLE automation.
    INCLUDE OLE2INCL.
    handles for OLE objects
    DATA: H_EXCEL TYPE OLE2_OBJECT,        " Excel object
          H_MAPL TYPE OLE2_OBJECT,         " list of workbooks
          H_MAP TYPE OLE2_OBJECT,          " workbook
          H_ZL TYPE OLE2_OBJECT,           " cell
          H_F TYPE OLE2_OBJECT.            " font
    TABLES: SPFLI.
    DATA  H TYPE I.
    table of flights
    DATA: IT_SPFLI LIKE SPFLI OCCURS 10 WITH HEADER LINE.
    *&   Event START-OF-SELECTION
    START-OF-SELECTION.
    read flights
      SELECT * FROM SPFLI INTO TABLE IT_SPFLI UP TO 10 ROWS.
    display header
      ULINE (61).
      WRITE: /     SY-VLINE NO-GAP,
              (3)  'Flg'(001) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,
              (4)  'Nr'(002) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,
              (20) 'Von'(003) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,
              (20) 'Nach'(004) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,
              (8)  'Zeit'(005) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP.
      ULINE /(61).
    display flights
      LOOP AT IT_SPFLI.
      WRITE: / SY-VLINE NO-GAP,
               IT_SPFLI-CARRID COLOR COL_KEY NO-GAP, SY-VLINE NO-GAP,
               IT_SPFLI-CONNID COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP,
               IT_SPFLI-CITYFROM COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP,
               IT_SPFLI-CITYTO COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP,
               IT_SPFLI-DEPTIME COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP.
      ENDLOOP.
      ULINE /(61).
    tell user what is going on
      CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
         EXPORTING
              PERCENTAGE = 0
               TEXT       = TEXT-007
           EXCEPTIONS
                OTHERS     = 1.
    start Excel
      CREATE OBJECT H_EXCEL 'EXCEL.APPLICATION'.
    PERFORM ERR_HDL.
      SET PROPERTY OF H_EXCEL  'Visible' = 1.
    CALL METHOD OF H_EXCEL 'FILESAVEAS' EXPORTING #1 = 'c:\kis_excel.xls'
    PERFORM ERR_HDL.
    tell user what is going on
      CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
         EXPORTING
              PERCENTAGE = 0
               TEXT       = TEXT-008
           EXCEPTIONS
                OTHERS     = 1.
    get list of workbooks, initially empty
      CALL METHOD OF H_EXCEL 'Workbooks' = H_MAPL.
      PERFORM ERR_HDL.
    add a new workbook
      CALL METHOD OF H_MAPL 'Add' = H_MAP.
      PERFORM ERR_HDL.
    tell user what is going on
      CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
         EXPORTING
              PERCENTAGE = 0
               TEXT       = TEXT-009
           EXCEPTIONS
                OTHERS     = 1.
    output column headings to active Excel sheet
      PERFORM FILL_CELL USING 1 1 1 'Flug'(001).
      PERFORM FILL_CELL USING 1 2 0 'Nr'(002).
      PERFORM FILL_CELL USING 1 3 1 'Von'(003).
      PERFORM FILL_CELL USING 1 4 1 'Nach'(004).
      PERFORM FILL_CELL USING 1 5 1 'Zeit'(005).
      LOOP AT IT_SPFLI.
    copy flights to active EXCEL sheet
        H = SY-TABIX + 1.
        PERFORM FILL_CELL USING H 1 0 IT_SPFLI-CARRID.
        PERFORM FILL_CELL USING H 2 0 IT_SPFLI-CONNID.
        PERFORM FILL_CELL USING H 3 0 IT_SPFLI-CITYFROM.
        PERFORM FILL_CELL USING H 4 0 IT_SPFLI-CITYTO.
        PERFORM FILL_CELL USING H 5 0 IT_SPFLI-DEPTIME.
      ENDLOOP.
    changes by Kishore  - start
    CALL METHOD OF H_EXCEL 'Workbooks' = H_MAPL.
      CALL METHOD OF H_EXCEL 'Worksheets' = H_MAPL." EXPORTING #1 = 2.
      PERFORM ERR_HDL.
    add a new workbook
      CALL METHOD OF H_MAPL 'Add' = H_MAP  EXPORTING #1 = 2.
      PERFORM ERR_HDL.
    tell user what is going on
      SET PROPERTY OF H_MAP 'NAME' = 'COPY'.
      CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
         EXPORTING
              PERCENTAGE = 0
               TEXT       = TEXT-009
           EXCEPTIONS
                OTHERS     = 1.
    output column headings to active Excel sheet
      PERFORM FILL_CELL USING 1 1 1 'Flug'(001).
      PERFORM FILL_CELL USING 1 2 0 'Nr'(002).
      PERFORM FILL_CELL USING 1 3 1 'Von'(003).
      PERFORM FILL_CELL USING 1 4 1 'Nach'(004).
      PERFORM FILL_CELL USING 1 5 1 'Zeit'(005).
      LOOP AT IT_SPFLI.
    copy flights to active EXCEL sheet
        H = SY-TABIX + 1.
        PERFORM FILL_CELL USING H 1 0 IT_SPFLI-CARRID.
        PERFORM FILL_CELL USING H 2 0 IT_SPFLI-CONNID.
        PERFORM FILL_CELL USING H 3 0 IT_SPFLI-CITYFROM.
        PERFORM FILL_CELL USING H 4 0 IT_SPFLI-CITYTO.
        PERFORM FILL_CELL USING H 5 0 IT_SPFLI-DEPTIME.
      ENDLOOP.
    changes by Kishore  - end
    disconnect from Excel
         CALL METHOD OF H_EXCEL 'FILESAVEAS' EXPORTING  #1 = 'C:\SKV.XLS'.
      FREE OBJECT H_EXCEL.
      PERFORM ERR_HDL.
          FORM FILL_CELL                                                *
          sets cell at coordinates i,j to value val boldtype bold       *
    FORM FILL_CELL USING I J BOLD VAL.
      CALL METHOD OF H_EXCEL 'Cells' = H_ZL EXPORTING #1 = I #2 = J.
      PERFORM ERR_HDL.
      SET PROPERTY OF H_ZL 'Value' = VAL .
      PERFORM ERR_HDL.
      GET PROPERTY OF H_ZL 'Font' = H_F.
      PERFORM ERR_HDL.
      SET PROPERTY OF H_F 'Bold' = BOLD .
      PERFORM ERR_HDL.
    ENDFORM.
    *&      Form  ERR_HDL
          outputs OLE error if any                                       *
    -->  p1        text
    <--  p2        text
    FORM ERR_HDL.
    IF SY-SUBRC <> 0.
      WRITE: / 'Fehler bei OLE-Automation:'(010), SY-SUBRC.
      STOP.
    ENDIF.
    ENDFORM.                    " ERR_HDL
    Please note that this example maybe slow at filling the excel table
    (perhaps four fields per second on a 900 MHz machine - almost 30 seconds
    for a short example).
    To get the data on properties and methods - there is a bit of smoke and mirrors
    going on here; they are EXCEL properties and methods, not sap ones - so you need
    to look at excel help to determine how a particular function is structured. then
    build the block in sap, as shown in the example.
    If you only want to transfer the data to Excel like when you transfer the data from
    ALV to Excel simply use the Function Modules:
    XXL_SIMPLE_API
    If you want more modifications when you transfer it to Excel use:
    XXL_FULL_API

  • Downloading to Excel Sheet from ALV display

    Hi Friends,
    Here i am displaying data in ALV grid. i want to download data to excel file . My data is stored in a field symbol.Could you please tell me how to download this? Currently i am trying with
    CALL FUNCTION 'OLE_SERVER_CHECK'
    CALL FUNCTION 'XXL_SIMPLE_API'
    But i am not getting the result.
    Thanks.

    Download a report to excel with format (border, color cell, etc)
    Try this program...
    Code:
    REPORT ZTEST NO STANDARD PAGE HEADING.
    this report demonstrates how to send some ABAP data to an
    EXCEL sheet using OLE automation.
    INCLUDE OLE2INCL.
    handles for OLE objects
    DATA: H_EXCEL TYPE OLE2_OBJECT,        " Excel object
          H_MAPL TYPE OLE2_OBJECT,         " list of workbooks
          H_MAP TYPE OLE2_OBJECT,          " workbook
          H_ZL TYPE OLE2_OBJECT,           " cell
          H_F TYPE OLE2_OBJECT.            " font
    TABLES: SPFLI.
    DATA  H TYPE I.
    table of flights
    DATA: IT_SPFLI LIKE SPFLI OCCURS 10 WITH HEADER LINE.
    *&   Event START-OF-SELECTION
    START-OF-SELECTION.
    read flights
      SELECT * FROM SPFLI INTO TABLE IT_SPFLI UP TO 10 ROWS.
    display header
      ULINE (61).
      WRITE: /     SY-VLINE NO-GAP,
              (3)  'Flg'(001) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,
              (4)  'Nr'(002) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,
              (20) 'Von'(003) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,
              (20) 'Nach'(004) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,
              (8)  'Zeit'(005) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP.
      ULINE /(61).
    display flights
      LOOP AT IT_SPFLI.
      WRITE: / SY-VLINE NO-GAP,
               IT_SPFLI-CARRID COLOR COL_KEY NO-GAP, SY-VLINE NO-GAP,
               IT_SPFLI-CONNID COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP,
               IT_SPFLI-CITYFROM COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP,
               IT_SPFLI-CITYTO COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP,
               IT_SPFLI-DEPTIME COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP.
      ENDLOOP.
      ULINE /(61).
    tell user what is going on
      CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
         EXPORTING
              PERCENTAGE = 0
               TEXT       = TEXT-007
           EXCEPTIONS
                OTHERS     = 1.
    start Excel
      CREATE OBJECT H_EXCEL 'EXCEL.APPLICATION'.
    PERFORM ERR_HDL.
      SET PROPERTY OF H_EXCEL  'Visible' = 1.
    CALL METHOD OF H_EXCEL 'FILESAVEAS' EXPORTING #1 = 'c:\kis_excel.xls'
    PERFORM ERR_HDL.
    tell user what is going on
      CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
         EXPORTING
              PERCENTAGE = 0
               TEXT       = TEXT-008
           EXCEPTIONS
                OTHERS     = 1.
    get list of workbooks, initially empty
      CALL METHOD OF H_EXCEL 'Workbooks' = H_MAPL.
      PERFORM ERR_HDL.
    add a new workbook
      CALL METHOD OF H_MAPL 'Add' = H_MAP.
      PERFORM ERR_HDL.
    tell user what is going on
      CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
         EXPORTING
              PERCENTAGE = 0
               TEXT       = TEXT-009
           EXCEPTIONS
                OTHERS     = 1.
    output column headings to active Excel sheet
      PERFORM FILL_CELL USING 1 1 1 'Flug'(001).
      PERFORM FILL_CELL USING 1 2 0 'Nr'(002).
      PERFORM FILL_CELL USING 1 3 1 'Von'(003).
      PERFORM FILL_CELL USING 1 4 1 'Nach'(004).
      PERFORM FILL_CELL USING 1 5 1 'Zeit'(005).
      LOOP AT IT_SPFLI.
    copy flights to active EXCEL sheet
        H = SY-TABIX + 1.
        PERFORM FILL_CELL USING H 1 0 IT_SPFLI-CARRID.
        PERFORM FILL_CELL USING H 2 0 IT_SPFLI-CONNID.
        PERFORM FILL_CELL USING H 3 0 IT_SPFLI-CITYFROM.
        PERFORM FILL_CELL USING H 4 0 IT_SPFLI-CITYTO.
        PERFORM FILL_CELL USING H 5 0 IT_SPFLI-DEPTIME.
      ENDLOOP.
    changes by Kishore  - start
    CALL METHOD OF H_EXCEL 'Workbooks' = H_MAPL.
      CALL METHOD OF H_EXCEL 'Worksheets' = H_MAPL." EXPORTING #1 = 2.
      PERFORM ERR_HDL.
    add a new workbook
      CALL METHOD OF H_MAPL 'Add' = H_MAP  EXPORTING #1 = 2.
      PERFORM ERR_HDL.
    tell user what is going on
      SET PROPERTY OF H_MAP 'NAME' = 'COPY'.
      CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
         EXPORTING
              PERCENTAGE = 0
               TEXT       = TEXT-009
           EXCEPTIONS
                OTHERS     = 1.
    output column headings to active Excel sheet
      PERFORM FILL_CELL USING 1 1 1 'Flug'(001).
      PERFORM FILL_CELL USING 1 2 0 'Nr'(002).
      PERFORM FILL_CELL USING 1 3 1 'Von'(003).
      PERFORM FILL_CELL USING 1 4 1 'Nach'(004).
      PERFORM FILL_CELL USING 1 5 1 'Zeit'(005).
      LOOP AT IT_SPFLI.
    copy flights to active EXCEL sheet
        H = SY-TABIX + 1.
        PERFORM FILL_CELL USING H 1 0 IT_SPFLI-CARRID.
        PERFORM FILL_CELL USING H 2 0 IT_SPFLI-CONNID.
        PERFORM FILL_CELL USING H 3 0 IT_SPFLI-CITYFROM.
        PERFORM FILL_CELL USING H 4 0 IT_SPFLI-CITYTO.
        PERFORM FILL_CELL USING H 5 0 IT_SPFLI-DEPTIME.
      ENDLOOP.
    changes by Kishore  - end
    disconnect from Excel
         CALL METHOD OF H_EXCEL 'FILESAVEAS' EXPORTING  #1 = 'C:\SKV.XLS'.
      FREE OBJECT H_EXCEL.
      PERFORM ERR_HDL.
          FORM FILL_CELL                                                *
          sets cell at coordinates i,j to value val boldtype bold       *
    FORM FILL_CELL USING I J BOLD VAL.
      CALL METHOD OF H_EXCEL 'Cells' = H_ZL EXPORTING #1 = I #2 = J.
      PERFORM ERR_HDL.
      SET PROPERTY OF H_ZL 'Value' = VAL .
      PERFORM ERR_HDL.
      GET PROPERTY OF H_ZL 'Font' = H_F.
      PERFORM ERR_HDL.
      SET PROPERTY OF H_F 'Bold' = BOLD .
      PERFORM ERR_HDL.
    ENDFORM.
    *&      Form  ERR_HDL
          outputs OLE error if any                                       *
    -->  p1        text
    <--  p2        text
    FORM ERR_HDL.
    IF SY-SUBRC <> 0.
      WRITE: / 'Fehler bei OLE-Automation:'(010), SY-SUBRC.
      STOP.
    ENDIF.
    ENDFORM.                    " ERR_HDL
    Regards,
    Pavan

  • ALV colouring download to excel sheet

    Hi Experts ,
    I have a requirement in which I have coloured the cells of the ALV display , in order to highlight them.
    I have made use of 'REUSE_ALV_GRID_DISPLAY' FM for displaying ALV.
    When I  download this output to an excel sheet , the colour filled in various cells disappears.
    Can someone let me know that , is it possible to retain this colour of the cell even after ALV download to an excel sheet?
    Thanks in Advance !!!

    Hi retwika
    I had searched on this previously and found out the following code,for download a report to excel with format (border, color cell, etc) 
    REPORT ZSIRI NO STANDARD PAGE HEADING.
    * this report demonstrates how to send some ABAP data to an
    * EXCEL sheet using OLE automation.
    INCLUDE OLE2INCL.
    * handles for OLE objects
    DATA: H_EXCEL TYPE OLE2_OBJECT,        " Excel object
          H_MAPL TYPE OLE2_OBJECT,         " list of workbooks
          H_MAP TYPE OLE2_OBJECT,          " workbook
          H_ZL TYPE OLE2_OBJECT,           " cell
          H_F TYPE OLE2_OBJECT.            " font
    TABLES: SPFLI.
    DATA  H TYPE I.
    * table of flights
    DATA: IT_SPFLI LIKE SPFLI OCCURS 10 WITH HEADER LINE.
    *&   Event START-OF-SELECTION
    START-OF-SELECTION.
    * read flights
      SELECT * FROM SPFLI INTO TABLE IT_SPFLI UP TO 10 ROWS.
    * display header
      ULINE (61).
      WRITE: /     SY-VLINE NO-GAP,
              (3)  'Flg'(001) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,
              (4)  'Nr'(002) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,
              (20) 'Von'(003) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,
              (20) 'Nach'(004) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,
              (8)  'Zeit'(005) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP.
      ULINE /(61).
    * display flights
      LOOP AT IT_SPFLI.
      WRITE: / SY-VLINE NO-GAP,
               IT_SPFLI-CARRID COLOR COL_KEY NO-GAP, SY-VLINE NO-GAP,
               IT_SPFLI-CONNID COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP,
               IT_SPFLI-CITYFROM COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP,
               IT_SPFLI-CITYTO COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP,
               IT_SPFLI-DEPTIME COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP.
      ENDLOOP.
      ULINE /(61).
    * tell user what is going on
      CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
         EXPORTING
    *           PERCENTAGE = 0
               TEXT       = TEXT-007
           EXCEPTIONS
                OTHERS     = 1.
    * start Excel
      CREATE OBJECT H_EXCEL 'EXCEL.APPLICATION'.
    *  PERFORM ERR_HDL.
      SET PROPERTY OF H_EXCEL  'Visible' = 1.
    *  CALL METHOD OF H_EXCEL 'FILESAVEAS' EXPORTING #1 = 'c:\kis_excel.xls'
    *  PERFORM ERR_HDL.
    * tell user what is going on
      CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
         EXPORTING
    *           PERCENTAGE = 0
               TEXT       = TEXT-008
           EXCEPTIONS
                OTHERS     = 1.
    * get list of workbooks, initially empty
      CALL METHOD OF H_EXCEL 'Workbooks' = H_MAPL.
      PERFORM ERR_HDL.
    * add a new workbook
      CALL METHOD OF H_MAPL 'Add' = H_MAP.
      PERFORM ERR_HDL.
    * tell user what is going on
      CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
         EXPORTING
    *           PERCENTAGE = 0
               TEXT       = TEXT-009
           EXCEPTIONS
                OTHERS     = 1.
    * output column headings to active Excel sheet
      PERFORM FILL_CELL USING 1 1 1 'Flug'(001).
      PERFORM FILL_CELL USING 1 2 0 'Nr'(002).
      PERFORM FILL_CELL USING 1 3 1 'Von'(003).
      PERFORM FILL_CELL USING 1 4 1 'Nach'(004).
      PERFORM FILL_CELL USING 1 5 1 'Zeit'(005).
      LOOP AT IT_SPFLI.
    * copy flights to active EXCEL sheet
        H = SY-TABIX + 1.
        PERFORM FILL_CELL USING H 1 0 IT_SPFLI-CARRID.
        PERFORM FILL_CELL USING H 2 0 IT_SPFLI-CONNID.
        PERFORM FILL_CELL USING H 3 0 IT_SPFLI-CITYFROM.
        PERFORM FILL_CELL USING H 4 0 IT_SPFLI-CITYTO.
        PERFORM FILL_CELL USING H 5 0 IT_SPFLI-DEPTIME.
      ENDLOOP.
    * changes by Kishore  - start
    *  CALL METHOD OF H_EXCEL 'Workbooks' = H_MAPL.
      CALL METHOD OF H_EXCEL 'Worksheets' = H_MAPL." EXPORTING #1 = 2.
      PERFORM ERR_HDL.
    * add a new workbook
      CALL METHOD OF H_MAPL 'Add' = H_MAP  EXPORTING #1 = 2.
      PERFORM ERR_HDL.
    * tell user what is going on
      SET PROPERTY OF H_MAP 'NAME' = 'COPY'.
      CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
         EXPORTING
    *           PERCENTAGE = 0
               TEXT       = TEXT-009
           EXCEPTIONS
                OTHERS     = 1.
    * output column headings to active Excel sheet
      PERFORM FILL_CELL USING 1 1 1 'Flug'(001).
      PERFORM FILL_CELL USING 1 2 0 'Nr'(002).
      PERFORM FILL_CELL USING 1 3 1 'Von'(003).
      PERFORM FILL_CELL USING 1 4 1 'Nach'(004).
      PERFORM FILL_CELL USING 1 5 1 'Zeit'(005).
      LOOP AT IT_SPFLI.
    * copy flights to active EXCEL sheet
        H = SY-TABIX + 1.
        PERFORM FILL_CELL USING H 1 0 IT_SPFLI-CARRID.
        PERFORM FILL_CELL USING H 2 0 IT_SPFLI-CONNID.
        PERFORM FILL_CELL USING H 3 0 IT_SPFLI-CITYFROM.
        PERFORM FILL_CELL USING H 4 0 IT_SPFLI-CITYTO.
        PERFORM FILL_CELL USING H 5 0 IT_SPFLI-DEPTIME.
      ENDLOOP.
    * changes by Kishore  - end
    * disconnect from Excel
    *      CALL METHOD OF H_EXCEL 'FILESAVEAS' EXPORTING  #1 = 'C:\SKV.XLS'.
      FREE OBJECT H_EXCEL.
      PERFORM ERR_HDL.
    *       FORM FILL_CELL                                                *
    *       sets cell at coordinates i,j to value val boldtype bold       *
    FORM FILL_CELL USING I J BOLD VAL.
      CALL METHOD OF H_EXCEL 'Cells' = H_ZL EXPORTING #1 = I #2 = J.
      PERFORM ERR_HDL.
      SET PROPERTY OF H_ZL 'Value' = VAL .
      PERFORM ERR_HDL.
      GET PROPERTY OF H_ZL 'Font' = H_F.
      PERFORM ERR_HDL.
      SET PROPERTY OF H_F 'Bold' = BOLD .
      PERFORM ERR_HDL.
    ENDFORM.
    *&      Form  ERR_HDL
    *       outputs OLE error if any                                       *
    *  -->  p1        text
    *  <--  p2        text
    FORM ERR_HDL.
    IF SY-SUBRC <> 0.
      WRITE: / 'Fehler bei OLE-Automation:'(010), SY-SUBRC.
      STOP.
    ENDIF.
    ENDFORM.                    " ERR_HDL
    Look out the changes
    Revert if any prblem
    Thanks and Regards
    Srikanth.P

  • Problem when down loading a simple report to Excel sheet

    HI Frenz,
    When I download a Simple report to excel , The Excel shows a blank column in between two column, which should not be the case.
    Kindly let me know ASAP
    Regards
    Irfan

    Hi,
    Check out the below samle code
    Download a report to excel with format (border, color cell, etc) 
    REPORT ZSIRI NO STANDARD PAGE HEADING.
    * this report demonstrates how to send some ABAP data to an
    * EXCEL sheet using OLE automation.
    INCLUDE OLE2INCL.
    * handles for OLE objects
    DATA: H_EXCEL TYPE OLE2_OBJECT,        " Excel object
          H_MAPL TYPE OLE2_OBJECT,         " list of workbooks
          H_MAP TYPE OLE2_OBJECT,          " workbook
          H_ZL TYPE OLE2_OBJECT,           " cell
          H_F TYPE OLE2_OBJECT.            " font
    TABLES: SPFLI.
    DATA  H TYPE I.
    * table of flights
    DATA: IT_SPFLI LIKE SPFLI OCCURS 10 WITH HEADER LINE.
    *&   Event START-OF-SELECTION
    START-OF-SELECTION.
    * read flights
      SELECT * FROM SPFLI INTO TABLE IT_SPFLI UP TO 10 ROWS.
    * display header
      ULINE (61).
      WRITE: /     SY-VLINE NO-GAP,
              (3)  'Flg'(001) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,
              (4)  'Nr'(002) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,
              (20) 'Von'(003) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,
              (20) 'Nach'(004) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,
              (8)  'Zeit'(005) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP.
      ULINE /(61).
    * display flights
      LOOP AT IT_SPFLI.
      WRITE: / SY-VLINE NO-GAP,
               IT_SPFLI-CARRID COLOR COL_KEY NO-GAP, SY-VLINE NO-GAP,
               IT_SPFLI-CONNID COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP,
               IT_SPFLI-CITYFROM COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP,
               IT_SPFLI-CITYTO COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP,
               IT_SPFLI-DEPTIME COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP.
      ENDLOOP.
      ULINE /(61).
    * tell user what is going on
      CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
         EXPORTING
    *           PERCENTAGE = 0
               TEXT       = TEXT-007
           EXCEPTIONS
                OTHERS     = 1.
    * start Excel
      CREATE OBJECT H_EXCEL 'EXCEL.APPLICATION'.
    *  PERFORM ERR_HDL.
      SET PROPERTY OF H_EXCEL  'Visible' = 1.
    *  CALL METHOD OF H_EXCEL 'FILESAVEAS' EXPORTING #1 = 'c:\kis_excel.xls'
    *  PERFORM ERR_HDL.
    * tell user what is going on
      CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
         EXPORTING
    *           PERCENTAGE = 0
               TEXT       = TEXT-008
           EXCEPTIONS
                OTHERS     = 1.
    * get list of workbooks, initially empty
      CALL METHOD OF H_EXCEL 'Workbooks' = H_MAPL.
      PERFORM ERR_HDL.
    * add a new workbook
      CALL METHOD OF H_MAPL 'Add' = H_MAP.
      PERFORM ERR_HDL.
    * tell user what is going on
      CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
         EXPORTING
    *           PERCENTAGE = 0
               TEXT       = TEXT-009
           EXCEPTIONS
                OTHERS     = 1.
    * output column headings to active Excel sheet
      PERFORM FILL_CELL USING 1 1 1 'Flug'(001).
      PERFORM FILL_CELL USING 1 2 0 'Nr'(002).
      PERFORM FILL_CELL USING 1 3 1 'Von'(003).
      PERFORM FILL_CELL USING 1 4 1 'Nach'(004).
      PERFORM FILL_CELL USING 1 5 1 'Zeit'(005).
      LOOP AT IT_SPFLI.
    * copy flights to active EXCEL sheet
        H = SY-TABIX + 1.
        PERFORM FILL_CELL USING H 1 0 IT_SPFLI-CARRID.
        PERFORM FILL_CELL USING H 2 0 IT_SPFLI-CONNID.
        PERFORM FILL_CELL USING H 3 0 IT_SPFLI-CITYFROM.
        PERFORM FILL_CELL USING H 4 0 IT_SPFLI-CITYTO.
        PERFORM FILL_CELL USING H 5 0 IT_SPFLI-DEPTIME.
      ENDLOOP.
    * changes by Kishore  - start
    *  CALL METHOD OF H_EXCEL 'Workbooks' = H_MAPL.
      CALL METHOD OF H_EXCEL 'Worksheets' = H_MAPL." EXPORTING #1 = 2.
      PERFORM ERR_HDL.
    * add a new workbook
      CALL METHOD OF H_MAPL 'Add' = H_MAP  EXPORTING #1 = 2.
      PERFORM ERR_HDL.
    * tell user what is going on
      SET PROPERTY OF H_MAP 'NAME' = 'COPY'.
      CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
         EXPORTING
    *           PERCENTAGE = 0
               TEXT       = TEXT-009
           EXCEPTIONS
                OTHERS     = 1.
    * output column headings to active Excel sheet
      PERFORM FILL_CELL USING 1 1 1 'Flug'(001).
      PERFORM FILL_CELL USING 1 2 0 'Nr'(002).
      PERFORM FILL_CELL USING 1 3 1 'Von'(003).
      PERFORM FILL_CELL USING 1 4 1 'Nach'(004).
      PERFORM FILL_CELL USING 1 5 1 'Zeit'(005).
      LOOP AT IT_SPFLI.
    * copy flights to active EXCEL sheet
        H = SY-TABIX + 1.
        PERFORM FILL_CELL USING H 1 0 IT_SPFLI-CARRID.
        PERFORM FILL_CELL USING H 2 0 IT_SPFLI-CONNID.
        PERFORM FILL_CELL USING H 3 0 IT_SPFLI-CITYFROM.
        PERFORM FILL_CELL USING H 4 0 IT_SPFLI-CITYTO.
        PERFORM FILL_CELL USING H 5 0 IT_SPFLI-DEPTIME.
      ENDLOOP.
    * changes by Kishore  - end
    * disconnect from Excel
    *      CALL METHOD OF H_EXCEL 'FILESAVEAS' EXPORTING  #1 = 'C:\SKV.XLS'.
      FREE OBJECT H_EXCEL.
      PERFORM ERR_HDL.
    *       FORM FILL_CELL                                                *
    *       sets cell at coordinates i,j to value val boldtype bold       *
    FORM FILL_CELL USING I J BOLD VAL.
      CALL METHOD OF H_EXCEL 'Cells' = H_ZL EXPORTING #1 = I #2 = J.
      PERFORM ERR_HDL.
      SET PROPERTY OF H_ZL 'Value' = VAL .
      PERFORM ERR_HDL.
      GET PROPERTY OF H_ZL 'Font' = H_F.
      PERFORM ERR_HDL.
      SET PROPERTY OF H_F 'Bold' = BOLD .
      PERFORM ERR_HDL.
    ENDFORM.
    *&      Form  ERR_HDL
    *       outputs OLE error if any                                       *
    *  -->  p1        text
    *  <--  p2        text
    FORM ERR_HDL.
    IF SY-SUBRC <> 0.
      WRITE: / 'Fehler bei OLE-Automation:'(010), SY-SUBRC.
      STOP.
    ENDIF.
    ENDFORM.                    " ERR_HDL
    Cheers,
    Chandru

  • I want to download a report into Excel sheet with color Heading..Is it Poss

    Hi All
    I want to download error records into Excel sheet with color Heading..Is it Possible to download into excel with Color Heading?
    here i am <b>using the 3 sheets in one</b>
    t_error-bkpf -> Sheet1
    t_error-bseg-> sheet 2
    t-error-bsec -> sheet3.
    Rgds
    Raghav

    <b>The following thread has the code which will put data into multiple sheets</b>
    Download to multiple sheets in Excel
    FOR COLOR LOGIC  JUST REFER THIS PROGRAM
    *& Report  ZNEGI17                                                     *
    REPORT  ZNEGI17  NO STANDARD PAGE HEADING.
    * this report demonstrates how to send some ABAP data to an
    * EXCEL sheet using OLE automation.
    INCLUDE OLE2INCL.
    * handles for OLE objects
    DATA: H_EXCEL TYPE OLE2_OBJECT, " Excel object
    H_MAPL TYPE OLE2_OBJECT, " list of workbooks
    H_MAP TYPE OLE2_OBJECT, " workbook
    H_ZL TYPE OLE2_OBJECT, " cell
    H_F TYPE OLE2_OBJECT. " font
    TABLES: SPFLI.
    DATA H TYPE I.
    * table of flights
    DATA: IT_SPFLI LIKE SPFLI OCCURS 10 WITH HEADER LINE.
    *& Event START-OF-SELECTION
    START-OF-SELECTION.
    * read flights
    SELECT * FROM SPFLI INTO TABLE IT_SPFLI UP TO 10 ROWS.
    * display header
    ULINE (61).
    WRITE: / SY-VLINE NO-GAP,
    (3) 'Flg'(001) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,
    (4) 'Nr'(002) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,
    (20) 'Von'(003) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,
    (20) 'Nach'(004) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,
    (8) 'Zeit'(005) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP.
    ULINE /(61).
    * display flights
    LOOP AT IT_SPFLI.
    WRITE: / SY-VLINE NO-GAP,
    IT_SPFLI-CARRID COLOR COL_KEY NO-GAP, SY-VLINE NO-GAP,
    IT_SPFLI-CONNID COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP,
    IT_SPFLI-CITYFROM COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP,
    IT_SPFLI-CITYTO COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP,
    IT_SPFLI-DEPTIME COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP.
    ENDLOOP.
    ULINE /(61).
    * tell user what is going on
    CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
    EXPORTING
    * PERCENTAGE = 0
    TEXT = TEXT-007
    EXCEPTIONS
    OTHERS = 1.
    * start Excel
    CREATE OBJECT H_EXCEL 'EXCEL.APPLICATION'.
    * PERFORM ERR_HDL.
    SET PROPERTY OF H_EXCEL 'Visible' = 1.
    * CALL METHOD OF H_EXCEL 'FILESAVEAS' EXPORTING #1 = 'c:kis_excel.xls'
    * PERFORM ERR_HDL.
    * tell user what is going on
    CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
    EXPORTING
    * PERCENTAGE = 0
    TEXT = TEXT-008
    EXCEPTIONS
    OTHERS = 1.
    * get list of workbooks, initially empty
    CALL METHOD OF H_EXCEL 'Workbooks' = H_MAPL.
    PERFORM ERR_HDL.
    * add a new workbook
    CALL METHOD OF H_MAPL 'Add' = H_MAP.
    PERFORM ERR_HDL.
    * tell user what is going on
    * CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
    * EXPORTING
    ** PERCENTAGE = 0
    * TEXT = TEXT-009
    * EXCEPTIONS
    * OTHERS = 1.
    * output column headings to active Excel sheet
    PERFORM FILL_CELL1 USING 1 1 1 'Flug'(001).
    PERFORM FILL_CELL1 USING 1 2 0 'Nr'(002).
    PERFORM FILL_CELL1 USING 1 3 1 'Von'(003).
    PERFORM FILL_CELL1 USING 1 4 1 'Nach'(004).
    PERFORM FILL_CELL1 USING 1 5 1 'Zeit'(005).
    LOOP AT IT_SPFLI.
    * copy flights to active EXCEL sheet
    H = SY-TABIX + 1.
    PERFORM FILL_CELL USING H 1 0 IT_SPFLI-CARRID.
    PERFORM FILL_CELL USING H 2 0 IT_SPFLI-CONNID.
    PERFORM FILL_CELL USING H 3 0 IT_SPFLI-CITYFROM.
    PERFORM FILL_CELL USING H 4 0 IT_SPFLI-CITYTO.
    PERFORM FILL_CELL USING H 5 0 IT_SPFLI-DEPTIME.
    ENDLOOP.
    * changes by Kishore - start
    * CALL METHOD OF H_EXCEL 'Workbooks' = H_MAPL.
    CALL METHOD OF H_EXCEL 'Worksheets' = H_MAPL." EXPORTING #1 = 2.
    PERFORM ERR_HDL.
    * add a new workbook
    CALL METHOD OF H_MAPL 'Add' = H_MAP EXPORTING #1 = 2.
    PERFORM ERR_HDL.
    * tell user what is going on
    SET PROPERTY OF H_MAP 'NAME' = 'COPY'.
    * CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
    * EXPORTING
    ** PERCENTAGE = 0
    * TEXT = TEXT-009
    * EXCEPTIONS
    * OTHERS = 1.
    * output column headings to active Excel sheet
    PERFORM FILL_CELL1 USING 1 1 1 'Flug'(001).
    PERFORM FILL_CELL1 USING 1 2 0 'Nr'(002).
    PERFORM FILL_CELL1 USING 1 3 1 'Von'(003).
    PERFORM FILL_CELL1 USING 1 4 1 'Nach'(004).
    PERFORM FILL_CELL1 USING 1 5 1 'Zeit'(005).
    LOOP AT IT_SPFLI.
    * copy flights to active EXCEL sheet
    H = SY-TABIX + 1.
    PERFORM FILL_CELL USING H 1 0 IT_SPFLI-CARRID.
    PERFORM FILL_CELL USING H 2 0 IT_SPFLI-CONNID.
    PERFORM FILL_CELL USING H 3 0 IT_SPFLI-CITYFROM.
    PERFORM FILL_CELL USING H 4 0 IT_SPFLI-CITYTO.
    PERFORM FILL_CELL USING H 5 0 IT_SPFLI-DEPTIME.
    ENDLOOP.
    * changes by Kishore - end
    * disconnect from Excel
    * CALL METHOD OF H_EXCEL 'FILESAVEAS' EXPORTING #1 = 'C:SKV.XLS'.
    FREE OBJECT H_EXCEL.
    PERFORM ERR_HDL.
    * FORM FILL_CELL *
    * sets cell at coordinates i,j to value val boldtype bold *
    FORM FILL_CELL1 USING I J BOLD VAL.
    data : color(5) type x value 'H80000008'.
    CALL METHOD OF H_EXCEL 'Cells' = H_ZL EXPORTING #1 = I #2 = J.
    PERFORM ERR_HDL.
    SET PROPERTY OF H_ZL 'Value' = VAL .
    PERFORM ERR_HDL.
    GET PROPERTY OF H_ZL 'Font' = H_F.
    PERFORM ERR_HDL.
    SET PROPERTY OF H_F 'Bold' = BOLD .
    PERFORM ERR_HDL.
    SET PROPERTY OF H_F 'ColorIndex' = 3 .
    PERFORM ERR_HDL.
    ENDFORM.
    *& Form ERR_HDL
    * outputs OLE error if any *
    * --> p1 text
    * <-- p2 text
    FORM ERR_HDL.
    IF SY-SUBRC <> 0.
    WRITE: / 'Fehler bei OLE-Automation:'(010), SY-SUBRC.
    STOP.
    ENDIF.
    ENDFORM. " ERR_HDL
    *&      Form  FILL_CELL1
    *       text
    *      -->P_H  text
    *      -->P_1      text
    *      -->P_0      text
    *      -->P_IT_SPFLI_CARRID  text
    form FILL_CELL  using   I J BOLD VAL.
    CALL METHOD OF H_EXCEL 'Cells' = H_ZL EXPORTING #1 = I #2 = J.
    PERFORM ERR_HDL.
    SET PROPERTY OF H_ZL 'Value' = VAL .
    PERFORM ERR_HDL.
    GET PROPERTY OF H_ZL 'Font' = H_F.
    PERFORM ERR_HDL.
    endform.                    " FILL_CELL1
    kishan negi

  • Excel Sheet processing

    Dear Friends,
         I am looking for a Function module that can process multiple worksheets in a Excel Sheet. Can any one help me in this.
    Eg: I have a excel order form with several work sheets. first two work sheets describes the description of the order form. And the remaining worksheets contains the order details. I want to get each order details in to internal table.

    Uploading multiple multitab Excel sheets or Ranges from Front end to SAP
    Please refer to
    http://www.sap-img.com/abap/abap-object-oriented-spreadsheet-with-unlimited-power.htm
    Visit
    http://help.sap.com/saphelp_47x200/helpdata/en/e9/0be775408e11d1893b0000e8323c4f/frameset.htm
    and
    http://help.sap.com/saphelp_47x200/helpdata/en/e9/0be775408e11d1893b0000e8323c4f/frameset.htm
    You need some basic idea of range object in excel.
    You need to create XLS with named ranges or create ranges dynamically.
    This could be a neat way to upload XLS the OO way!
    The function Module zjnc_get_range reads 1 range into any Internal
    table.
    DATA: BEGIN OF it_test OCCURS 0,
            vpd  LIKE mseg-menge,
            vas  LIKE mkpf-budat,
            vkm  LIKE mseg-matnr,
          END OF it_test.
      CALL FUNCTION 'ZJNC_GET_RANGE'
        EXPORTING
          rangename       = 'test'
          itabname        = 'IT_TEST[]'
          irecname        = 'it_test'
          spreadsheetintf = spreadsheetintf.
    =Work!$A$14:$C$16 is range "test"
    Numbers & Character data are no problem BUT dates are.
    In Excel default date is mm/dd/yyyy but is dependent on PC's
    international setting which is normally default
    To Avoid any 5-March 3-May type mix-up, I have designed the FM so that you need to
    enter dates as 'dd.Mon.yyyy i.e. in Characters in "Internet Date Format"
    FUNCTION zjnc_get_range.
    ""Local interface:
    *"  IMPORTING
    *"     REFERENCE(RANGENAME) TYPE  C
    *"     REFERENCE(ITABNAME) TYPE  C
    *"     REFERENCE(IRECNAME) TYPE  C
    *"     REFERENCE(SPREADSHEETINTF) TYPE REF TO  I_OI_SPREADSHEET
    *"     REFERENCE(SPREADSHEETINTF) TYPE REF TO  I_OI_SPREADSHEET
      DATA:
        stru_ref    TYPE REF TO cl_abap_structdescr,
        comp_tab    TYPE abap_compdescr_tab,
        one_comp    TYPE abap_compdescr,
        one_name    TYPE string,
        type_ref    TYPE REF TO cl_abap_typedescr,
        is_ddic     TYPE abap_bool,
        lt_ddic     TYPE dd_x031l_table,
        wa_ddic     TYPE x031l.
      DATA: zjncranges    TYPE soi_range_list,
            zjnccontents  TYPE soi_generic_table,
            zjnconerange  TYPE soi_range_item,
            zjnconeitem   TYPE soi_generic_item,
            prevrow(4)    TYPE n,
            nrow(4)       TYPE n,
            ncolumn(4)    TYPE n,
            mystring      TYPE string,
            mydate        LIKE sy-datum.
      FIELD-SYMBOLS: <fs_type>  TYPE ANY,
                     <fs_table> TYPE STANDARD TABLE,
                     <fs_line>  TYPE ANY.
      CONCATENATE '(' sy-cprog ')' itabname INTO mystring.
      ASSIGN (mystring) TO <fs_table>.
      CONCATENATE '(' sy-cprog ')' irecname INTO mystring.
      ASSIGN (mystring) TO <fs_line>.
      stru_ref ?= cl_abap_structdescr=>describe_by_data( <fs_line> ).
      comp_tab = stru_ref->components.
      REFRESH zjncranges.
      MOVE rangename TO zjnconerange-name.
      APPEND zjnconerange TO zjncranges.
      CALL METHOD spreadsheetintf->get_ranges_data
        IMPORTING
          contents = zjnccontents
          error    = zjncerror
          retcode  = zjncretcode
        CHANGING
          ranges   = zjncranges.
      MOVE 0 TO prevrow.
      LOOP AT zjnccontents INTO zjnconeitem.
        MOVE zjnconeitem-row TO nrow.
        IF nrow <> prevrow.
          IF prevrow <> 0.
            APPEND <fs_line> TO <fs_table>.
          ENDIF.
          CLEAR <fs_line>.
          MOVE nrow TO prevrow.
        ENDIF.
        MOVE zjnconeitem-column TO ncolumn.
        READ TABLE comp_tab INDEX ncolumn INTO one_comp.
        CONCATENATE '(' sy-cprog ')' irecname '-' one_comp-name INTO one_name.
        ASSIGN (one_name) TO <fs_type>.
        IF one_comp-type_kind <> 'D'.
          MOVE zjnconeitem-value TO <fs_type>.
        ELSE.
          TRANSLATE zjnconeitem-value TO UPPER CASE.
          CALL FUNCTION 'CONVERSION_EXIT_SDATE_INPUT'
            EXPORTING
              input  = zjnconeitem-value
            IMPORTING
              output = mydate.
          MOVE mydate TO <fs_type>.
        ENDIF.
      ENDLOOP.
      IF prevrow <> 0.
        APPEND <fs_line> TO <fs_table>.
      ENDIF.
    ENDFUNCTION.
    Regards,
    Jagadish

  • Regarding saving of excel sheet to presentation server...

    Hi,
    am using OLE inorder to create the EXCEL sheet, but the problem is am not able to save it to presentation server using the following program.. We have to do it Manually..
    Please go through it and help me and how will i save it using programm...
    this report demonstrates how to send some ABAP data to an
    EXCEL sheet using OLE automation.
    INCLUDE ole2incl.
    handles for OLE objects
    DATA: h_excel TYPE ole2_object,        " Excel object
          h_mapl TYPE ole2_object,         " list of workbooks
          h_map TYPE ole2_object,          " workbook
          h_zl TYPE ole2_object,           " cell
          h_f TYPE ole2_object,            " font
          h_cell TYPE ole2_object,
          p_filename TYPE rlgrap-filename.
    TABLES: spfli.
    DATA  h TYPE i.
    table of flights
    DATA: vert TYPE numc2 VALUE '90'.
    DATA: h_format TYPE ole2_object,
          l_cols TYPE ole2_object,
          l_entcol TYPE ole2_object,
          color TYPE char1 VALUE '4'.
    DATA: it_spfli LIKE spfli OCCURS 10 WITH HEADER LINE.
    *&   Event START-OF-SELECTION
    START-OF-SELECTION.
    read flights
      SELECT * FROM spfli INTO TABLE it_spfli UP TO 10 ROWS.
    display header
      ULINE (61).
      WRITE: /     sy-vline NO-GAP,
              (3)  'Flg'(001) COLOR COL_HEADING NO-GAP, sy-vline NO-GAP,
              (4)  'Nr'(002) COLOR COL_HEADING NO-GAP, sy-vline NO-GAP,
              (20) 'Von'(003) COLOR COL_HEADING NO-GAP, sy-vline NO-GAP,
              (20) 'Nach'(004) COLOR COL_HEADING NO-GAP, sy-vline NO-GAP,
              (8)  'Zeit'(005) COLOR COL_HEADING NO-GAP, sy-vline NO-GAP.
      ULINE /(61).
    display flights
      LOOP AT it_spfli.
        WRITE: / sy-vline NO-GAP,
                 it_spfli-carrid COLOR COL_KEY NO-GAP, sy-vline NO-GAP,
                 it_spfli-connid COLOR COL_NORMAL NO-GAP, sy-vline NO-GAP,
                 it_spfli-cityfrom COLOR COL_NORMAL NO-GAP, sy-vline NO-GAP,
                 it_spfli-cityto COLOR COL_NORMAL NO-GAP, sy-vline NO-GAP,
                 it_spfli-deptime COLOR COL_NORMAL NO-GAP, sy-vline NO-GAP.
      ENDLOOP.
      ULINE /(61).
    tell user what is going on
      CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
         EXPORTING
              PERCENTAGE = 0
               text       = text-007
           EXCEPTIONS
                OTHERS     = 1.
    start Excel
      CREATE OBJECT h_excel 'EXCEL.APPLICATION'.
    PERFORM ERR_HDL.
      SET PROPERTY OF h_excel  'Visible' = 1.
      CALL METHOD OF h_mapl 'SaveAs' EXPORTING #1 = 'C:\Documents and Settings\jrozar\Desktop\SKV.XLS'.
    PERFORM ERR_HDL.
    tell user what is going on
      CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
         EXPORTING
              PERCENTAGE = 0
               text       = text-008
           EXCEPTIONS
                OTHERS     = 1.
    get list of workbooks, initially empty
      CALL METHOD OF h_excel 'Workbooks' = h_mapl.
      PERFORM err_hdl.
    add a new workbook
      CALL METHOD OF h_mapl 'Add' = h_map.
      PERFORM err_hdl.
    tell user what is going on
      CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
         EXPORTING
              PERCENTAGE = 0
               text       = text-009
           EXCEPTIONS
                OTHERS     = 1.
    output column headings to active Excel sheet
      PERFORM fill_cell1 USING 90 1 1 1 'Flug'(001).
      PERFORM fill_cell1 USING 90 1 2 0 'Nr'(002).
      PERFORM fill_cell1 USING 90 1 3 1 'Von'(003).
      PERFORM fill_cell1 USING 90 1 4 1 'Nach'(004).
      PERFORM fill_cell1 USING 90 1 5 1 'Zeit'(005).
      LOOP AT it_spfli.
    copy flights to active EXCEL sheet
        h = sy-tabix + 1.
        PERFORM fill_cell USING h 1 0 it_spfli-carrid.
        PERFORM fill_cell USING h 2 0 it_spfli-connid.
        PERFORM fill_cell USING h 3 0 it_spfli-cityfrom.
        PERFORM fill_cell USING h 4 0 it_spfli-cityto.
        PERFORM fill_cell USING h 5 0 it_spfli-deptime.
      ENDLOOP.
    changes by Kishore  - start
    CALL METHOD OF H_EXCEL 'Workbooks' = H_MAPL.
    CALL METHOD OF H_EXCEL 'Worksheets' = H_MAPL." EXPORTING #1 = 2.
    PERFORM ERR_HDL.
    add a new workbook
    CALL METHOD OF H_MAPL 'Add' = H_MAP  EXPORTING #1 = 2.
    PERFORM ERR_HDL.
    tell user what is going on
    SET PROPERTY OF H_MAP 'NAME' = 'COPY'.
    CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
        EXPORTING
              PERCENTAGE = 0
              TEXT       = TEXT-009
          EXCEPTIONS
               OTHERS     = 1.
    output column headings to active Excel sheet
    PERFORM FILL_CELL USING 1 1 1 'Flug'(001).
    PERFORM FILL_CELL USING 1 2 0 'Nr'(002).
    PERFORM FILL_CELL USING 1 3 1 'Von'(003).
    PERFORM FILL_CELL USING 1 4 1 'Nach'(004).
    PERFORM FILL_CELL USING 1 5 1 'Zeit'(005).
    LOOP AT IT_SPFLI.
    copy flights to active EXCEL sheet
       H = SY-TABIX + 1.
       PERFORM FILL_CELL USING H 1 0 IT_SPFLI-CARRID.
       PERFORM FILL_CELL USING H 2 0 IT_SPFLI-CONNID.
       PERFORM FILL_CELL USING H 3 0 IT_SPFLI-CITYFROM.
       PERFORM FILL_CELL USING H 4 0 IT_SPFLI-CITYTO.
       PERFORM FILL_CELL USING H 5 0 IT_SPFLI-DEPTIME.
    ENDLOOP.
    changes by Kishore  - end
    disconnect from Excel
    CALL METHOD OF H_MAPL 'Saveas' EXPORTING  #1 = 'C:\tst.xls'.
      p_filename = 'C:\tst.xls'.
      CALL METHOD OF h_mapl 'Saveas'
        EXPORTING
        #1 = p_filename.
      CALL METHOD OF h_excel 'Close'.
    FREE OBJECT H_EXCEL.
      PERFORM err_hdl.
          FORM FILL_CELL                                                *
          sets cell at coordinates i,j to value val boldtype bold       *
    FORM fill_cell USING i j bold val.
      CALL METHOD OF h_excel 'Cells' = h_zl EXPORTING #1 = i #2 = j.
      PERFORM err_hdl.
      CALL METHOD OF h_zl 'Interior' = h_format.
          IF J EQ  2.
          color = 2.
    SET PROPERTY OF h_format 'ColorIndex' = color.
        ELSE.
          color = 4.
        ENDIF.
      SET PROPERTY OF h_format 'ColorIndex' = color.
      CALL METHOD OF h_zl 'Columns' = l_cols
        EXPORTING
        #1 = 2.
      CALL METHOD OF l_cols 'EntireColumn' = l_entcol.
      CALL METHOD OF l_entcol 'Autofit'.
      SET PROPERTY OF h_zl 'Value' = val .
      PERFORM err_hdl.
      GET PROPERTY OF h_zl 'Font' = h_f.
      PERFORM err_hdl.
      SET PROPERTY OF h_f 'Bold' = bold .
      PERFORM err_hdl.
    ENDFORM.                    "FILL_CELL
    *&      Form  FILL_CELL1
          text
         -->VERT       text
         -->I          text
         -->J          text
         -->BOLD       text
         -->VAL        text
    FORM fill_cell1 USING vert i j bold val.
      CALL METHOD OF h_excel 'Cells' = h_zl EXPORTING #1 = i #2 = j.
      PERFORM err_hdl.
      SET PROPERTY OF h_zl 'Orientation' = vert.
      CALL METHOD OF h_zl 'Interior' = h_format.
        IF J EQ  2.
          color = 2.
    SET PROPERTY OF h_format 'ColorIndex' = color.
        ELSE.
          color = 4.
        ENDIF.
      SET PROPERTY OF h_format 'ColorIndex' = color.
      CALL METHOD OF h_zl 'Columns' = l_cols
        EXPORTING
        #1 = i.
      SET PROPERTY OF h_zl 'Value' = val .
      PERFORM err_hdl.
      GET PROPERTY OF h_zl 'Font' = h_f.
      PERFORM err_hdl.
      SET PROPERTY OF h_f 'Bold' = bold .
      PERFORM err_hdl.
    ENDFORM.                                                    "FILL_CELL1
    *&      Form  ERR_HDL
          outputs OLE error if any                                       *
    -->  p1        text
    <--  p2        text
    FORM err_hdl.
      IF sy-subrc <> 0.
        WRITE: / 'Fehler bei OLE-Automation:'(010), sy-subrc.
        STOP.
      ENDIF.
    ENDFORM.                    " ERR_HDL

    Hello Subhash,
    Try this
    data: sheet TYPE ole2_object.
    data: lv_file(512) default 'C:tst.xls'.
    * Save excel speadsheet to particular filename
      GET PROPERTY OF h_excel 'ActiveSheet' = sheet.
      CALL METHOD OF sheet 'SaveAs'
        EXPORTING
          #1 = lv_file     "filename
          #2 = 1.                      "fileFormat

  • Hi: working with excel sheet

    HI,
       Please i need the code to activate the excel worksheet
    cells after dowloading it to the desktop. I will appreciate your help.
    rgs
    p.kp

    Hi,
    <b>Demo Program</b>
    RSOLETT1
    RSDEMO01
    XXLTTEST
    XXLSTEST
    XXLFTEST
    Check this source Code ; Hope it helps
    REPORT  y_man_excel                             .
    * this report demonstrates how to send some ABAP data to an
    * EXCEL sheet using OLE automation.
    INCLUDE ole2incl.
    * handles for OLE objects
    DATA: o_excel       TYPE ole2_object,        " Excel object
          o_workbooks   TYPE ole2_object,         " list of workbooks
          o_worksheet   TYPE ole2_object,          " workbook
          h_zl TYPE ole2_object,           " cell
          h_f TYPE ole2_object.            " font
    TYPES: BEGIN OF ty_header,
              create_date  TYPE char20 ,
              nomship_ref  TYPE char20 ,
              offer        TYPE char20 ,
              conf_ref_no  TYPE char20 ,
              con_eff_date TYPE char20 ,
              status_date  TYPE char20 ,
              rej_text     TYPE char20 ,
              trf_date     TYPE char20 ,
              mprn         TYPE char20 ,
              mprn_status  TYPE char20 ,
              mam_app      TYPE char20 ,
              open_read    TYPE char22 ,
           END OF ty_header.
    CONSTANTS :
           lc_file_type  TYPE char10 VALUE 'DAT'.
    DATA : lit_ty_header TYPE TABLE OF ty_header,
           wa_ty_header  LIKE LINE  OF lit_ty_header,
           lv_file_name  TYPE string.
    CLEAR: lit_ty_header[],
           wa_ty_header,
           lv_file_name.
    * Table of Coulumn Names.
    wa_ty_header-create_date    = 'Column one' .
    wa_ty_header-nomship_ref    = 'Column Two' .
    wa_ty_header-offer          = 'Column there' .
    wa_ty_header-conf_ref_no    = 'Column Four' .
    wa_ty_header-con_eff_date   = 'Column five' .
    wa_ty_header-status_date    = 'Column Six' .
    wa_ty_header-rej_text       = 'Column Seven' .
    wa_ty_header-trf_date       = 'Column Eight' .
    wa_ty_header-mprn           = 'Column Nine' .
    wa_ty_header-mprn_status    = 'Column Ten' .
    wa_ty_header-mam_app        = 'Column Eleven' .
    wa_ty_header-open_read      = 'Column 12' .
    APPEND wa_ty_header TO lit_ty_header.
    * File Name
    CONCATENATE text-033
                sy-uname
                sy-datum
                sy-uzeit
                text-034
    INTO lv_file_name.
    CONDENSE lv_file_name.
    *&   Event START-OF-SELECTION
    START-OF-SELECTION.
    *----start Excel
      CREATE OBJECT o_excel 'EXCEL.APPLICATION'.
    *----Set non visible
      SET PROPERTY OF o_excel  'Visible' = 1.
    *----get list of workbooks, initially empty
      CALL METHOD OF o_excel 'Workbooks' = o_workbooks.
      PERFORM err_hdl.
    *----add a new workbook
      CALL METHOD OF o_workbooks 'Add' = o_worksheet.
    *  CALL METHOD OF o_worksheet 'Activate'.
    *  SET PROPERTY OF o_worksheet  'Name' = 'Page 1'.
      PERFORM err_hdl.
    * output column headings to active Excel sheet
      PERFORM fill_cell USING 1 1 1 'Flug'(001).
      PERFORM fill_cell USING 1 2 0 'Nr'(002).
      PERFORM fill_cell USING 1 3 1 'Von'(003).
      PERFORM fill_cell USING 1 4 1 'Nach'(004).
      PERFORM fill_cell USING 1 5 1 'Zeit'(005).
      CALL METHOD OF o_worksheet 'SAVEAS'
        EXPORTING
          #1 = 'c:kis_excel.xls'.
      FREE OBJECT o_excel.
      PERFORM err_hdl.
    *       FORM FILL_CELL                                                *
    *       sets cell at coordinates i,j to value val boldtype bold       *
    FORM fill_cell USING i j bold val.
      CALL METHOD OF o_excel 'Cells' = h_zl
        EXPORTING
          #1 = i
          #2 = j.
      PERFORM err_hdl.
      SET PROPERTY OF h_zl 'Value' = val .
      PERFORM err_hdl.
      GET PROPERTY OF h_zl 'Font' = h_f.
      PERFORM err_hdl.
      SET PROPERTY OF h_f 'Bold' = bold .
      PERFORM err_hdl.
    ENDFORM.                    "FILL_CELL
    *&      Form  ERR_HDL
    *       outputs OLE error if any                                       *
    *  -->  p1        text
    *  <--  p2        text
    FORM err_hdl.
      IF sy-subrc <> 0.
        WRITE: / 'error:-', sy-subrc.
        STOP.
      ENDIF.

  • Urgent:download data in differnt tabs of excel sheet

    Hi,
    I want to save data from internal table to different worksheet of an excel sheet file without using ole. I am having thousands of record in my internal table. Currently I am doing this by using OLE but its response time is very high. Plz suggest any other method with which we can do it fast.
    rely will be suitably rewarded
    Edited by: amit manglik on Jan 28, 2008 10:23 AM
    Edited by: amit manglik on Jan 29, 2008 10:18 AM

    hi,
    Refer sample code:
    Multiple excel sheets generation in a workbook
    CREATE OBJECT EXCEL 'EXCEL.SHEET'.
    GET PROPERTY OF EXCEL 'Application' = APPLICATION.
    SET PROPERTY OF APPLICATION 'Visible' = 1.
    CALL METHOD OF APPLICATION 'Workbooks' = BOOKS.
    CALL METHOD OF BOOKS 'Add' = BOOK.
    CALL METHOD OF BOOK 'WORKSHEETS' = SHEET.
    CALL METHOD OF SHEET 'ADD'.
    Fill all the sheets with relavant data
    PERFORM SHEET1 TABLES ITAB1.
    PERFORM SHEET2 TABLES ITAB2.
    PERFORM SHEET3 TABLES ITAB3.
    PERFORM SHEET4 TABLES ITAB4.
    Quit the excel after use
    CALL METHOD OF EXCEL 'QUIT'.
    FREE OBJECT: COLUMN,SHEET,BOOK,BOOKS,APPLICATION,EXCEL. "NO FLUSH.
    CLEAR V_SHEET.
    FORM FILL_CELL USING ROW COL VAL.
    CALL METHOD OF SHEET 'cells' = CELL NO FLUSH
    EXPORTING #1 = ROW #2 = COL.
    SET PROPERTY OF CELL 'value' = VAL.
    FREE OBJECT CELL NO FLUSH.
    ENDFORM. " FILL_CELL
    FORM SHEET1 TABLES ITAB1 STRUCTURE ITAB1.
    V_SHEET = Sheet Name.
    V_NO = V_NO + 1.
    CALL METHOD OF BOOK 'worksheets' = SHEET NO FLUSH EXPORTING #1 = V_NO.
    SET PROPERTY OF SHEET 'Name' = V_SHEET NO FLUSH.
    PERFORM FILL_SHEET1 TABLES ITAB1 USING V_NO V_SHEET.
    CALL METHOD OF SHEET 'Columns' = COLUMN.
    FREE OBJECT SHEET.
    CALL METHOD OF COLUMN 'Autofit'.
    FREE OBJECT COLUMN.
    ENDFORM.
    Repeat above procedure for all sheets you want to add
    FORM FILL_SHEET1
    TABLES ITAB1 STRUCTURE ITAB1
    USING V_NO V_SHEET.
    ROW = 1.
    PERFORM FILL_CELL USING ROW 1 'Column1 Name'.
    PERFORM FILL_CELL USING ROW 2 'Column2 Name'.
    PERFORM FILL_CELL USING ROW 3 'Column3 Name'.
    ROW = ROW + 1.
    LOOP AT ITAB1.
    PERFORM FILL_CELL USING ROW 1 ITAB1-Column1.
    PERFORM FILL_CELL USING ROW 2 ITAB1-Column2.
    PERFORM FILL_CELL USING ROW 3 ITAB1-Column3.
    ROW = ROW + 1.
    ENDLOOP.
    ENDFORM.
    Repeat above procedure for all sheets you want to add
    Also follow this link, for a simillar kind of download program.
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/c05db2ca-569e-2910-0784-fc06cc3be31d
    Hope this helps, Do reward.

Maybe you are looking for