Problem  in  excel  download using  OLE concept

Hi ,
    i am trying to  create two sheets using OLE concept.
i am able to create the excel successfully but i can't save it .
i have one problem .
GET PROPERTY OF excel 'ActiveSheet' = sheet.
CALL METHOD OF sheet 'FILESAVEAS' EXPORTING #1 = w_filename1.
IF sy-subrc eq 0.
the sy-subrc value comes as  2.
i am passing 'C:\SKD.XLS'  to  w_filename.
is anything wrong.
how can check  this method  and it's exceptions.

i am getting the file name from user input using the  method
*"Calling method for getting file name as saved by the user.
  CALL METHOD cl_gui_frontend_services=>file_save_dialog
    EXPORTING
      window_title         = w_title
    CHANGING
      filename             = w_filnam
      path                 = w_path
      fullpath             = w_filename1
    EXCEPTIONS
      cntl_error           = 1
      error_no_gui         = 2
      not_supported_by_gui = 3
      OTHERS               = 4.
w_filename1 is of sting type .
i am passing the  full  path to  it .
please  let  me  i am doing anything wrong .

Similar Messages

  • Problem with excel download using ALV_XXL_CALL

    Hi All,
    Standard program is using this FM ALV_XXL_CALL for downloading data into excel sheet.
    I am trying to download table data in the excel but the excel file is opened without data.
    I am unable to view data in the excel file(2007) after the execution of program.
    Any Help for the same will be highly appreciated.
    Thanks

    Often we face situations where we need to download internal table contents onto an Excel sheet. We are familiar with the function module WS_DOWNLOAD. Though this function module downloads the contents onto the Excel sheet, there cannot be any column headings or we cannot differentiate the primary keys just by seeing the Excel sheet.
    For this purpose, we can use the function module XXL_FULL_API. The Excel sheet which is generated by this function module contains the column headings and the key columns are highlighted with a different color. Other options that are available with this function module are we can swap two columns or supress a field from displaying on the Excel sheet. The simple code for the usage of this function module is given below.
    Program code :
    REPORT Excel.
    TABLES:
      sflight.
    header data................................
    DATA :
      header1 LIKE gxxlt_p-text VALUE 'Suresh',
      header2 LIKE gxxlt_p-text VALUE 'Excel sheet'.
    Internal table for holding the SFLIGHT data
    DATA BEGIN OF t_sflight OCCURS 0.
            INCLUDE STRUCTURE sflight.
    DATA END   OF t_sflight.
    Internal table for holding the horizontal key.
    DATA BEGIN OF  t_hkey OCCURS 0.
            INCLUDE STRUCTURE gxxlt_h.
    DATA END   OF t_hkey .
    Internal table for holding the vertical key.
    DATA BEGIN OF t_vkey OCCURS 0.
            INCLUDE STRUCTURE gxxlt_v.
    DATA END   OF t_vkey .
    Internal table for holding the online text....
    DATA BEGIN OF t_online OCCURS 0.
            INCLUDE STRUCTURE gxxlt_o.
    DATA END   OF t_online.
    Internal table to hold print text.............
    DATA BEGIN OF t_print OCCURS 0.
            INCLUDE STRUCTURE gxxlt_p.
    DATA END   OF t_print.
    Internal table to hold SEMA data..............
    DATA BEGIN OF t_sema OCCURS 0.
            INCLUDE STRUCTURE gxxlt_s.
    DATA END   OF t_sema.
    Retreiving data from sflight.
    SELECT * FROM sflight
             INTO TABLE t_sflight.
    Text which will be displayed online is declared here....
    t_online-line_no    = '1'.
    t_online-info_name  = 'Created by'.
    t_online-info_value = 'SURESH KUMAR PARVATHANENI'.
    APPEND t_online.
    Text which will be printed out..........................
    t_print-hf     = 'H'.
    t_print-lcr    = 'L'.
    t_print-line_no = '1'.
    t_print-text   = 'This is the header'.
    APPEND t_print.
    t_print-hf     = 'F'.
    t_print-lcr    = 'C'.
    t_print-line_no = '1'.
    t_print-text   = 'This is the footer'.
    APPEND t_print.
    Defining the vertical key columns.......
    t_vkey-col_no   = '1'.
    t_vkey-col_name = 'MANDT'.
    APPEND t_vkey.
    t_vkey-col_no   = '2'.
    t_vkey-col_name = 'CARRID'.
    APPEND t_vkey.
    t_vkey-col_no   = '3'.
    t_vkey-col_name = 'CONNID'.
    APPEND t_vkey.
    t_vkey-col_no   = '4'.
    t_vkey-col_name = 'FLDATE'.
    APPEND t_vkey.
    Header text for the data columns................
    t_hkey-row_no = '1'.
    t_hkey-col_no = 1.
    t_hkey-col_name = 'PRICE'.
    APPEND t_hkey.
    t_hkey-col_no = 2.
    t_hkey-col_name = 'CURRENCY'.
    APPEND t_hkey.
    t_hkey-col_no = 3.
    t_hkey-col_name = 'PLANETYPE'.
    APPEND t_hkey.
    t_hkey-col_no = 4.
    t_hkey-col_name = 'SEATSMAX'.
    APPEND t_hkey.
    t_hkey-col_no = 5.
    t_hkey-col_name = 'SEATSOCC'.
    APPEND t_hkey.
    t_hkey-col_no = 6.
    t_hkey-col_name = 'PAYMENTSUM'.
    APPEND t_hkey.
    populating the SEMA data..........................
    t_sema-col_no  = 1.
    t_sema-col_typ = 'STR'.
    t_sema-col_ops = 'DFT'.
    APPEND t_sema.
    t_sema-col_no = 2.
    APPEND t_sema.
    t_sema-col_no = 3.
    APPEND t_sema.
    t_sema-col_no = 4.
    APPEND t_sema.
    t_sema-col_no = 5.
    APPEND t_sema.
    t_sema-col_no = 6.
    APPEND t_sema.
    t_sema-col_no = 7.
    APPEND t_sema.
    t_sema-col_no = 8.
    APPEND t_sema.
    t_sema-col_no = 9.
    APPEND t_sema.
    t_sema-col_no = 10.
    t_sema-col_typ = 'NUM'.
    t_sema-col_ops = 'ADD'.
    APPEND t_sema.
    CALL FUNCTION 'XXL_FULL_API'
      EXPORTING
      DATA_ENDING_AT          = 54
      DATA_STARTING_AT        = 5
       filename                = 'TESTFILE'
       header_1                = header1
       header_2                = header2
       no_dialog               = 'X'
       no_start                = ' '
        n_att_cols              = 6
        n_hrz_keys              = 1
        n_vrt_keys              = 4
       sema_type               = 'X'
      SO_TITLE                = ' '
      TABLES
        data                    = t_sflight
        hkey                    = t_hkey
        online_text             = t_online
        print_text              = t_print
        sema                    = t_sema
        vkey                    = t_vkey
    EXCEPTIONS
       cancelled_by_user       = 1
       data_too_big            = 2
       dim_mismatch_data       = 3
       dim_mismatch_sema       = 4
       dim_mismatch_vkey       = 5
       error_in_hkey           = 6
       error_in_sema           = 7
       file_open_error         = 8
       file_write_error        = 9
       inv_data_range          = 10
       inv_winsys              = 11
       inv_xxl                 = 12
       OTHERS                  = 13
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    I hope it  might be of some help to you.
    Thanks & Regards,
    Radhika
    Edited by: Radhika Parag Rajopadhye on Dec 1, 2009 8:27 AM
    Edited by: Radhika Parag Rajopadhye on Dec 1, 2009 8:27 AM

  • ALV download to Excel onto desktop using OLE concept.

    Hi Experts,
    I requriement is , through my se38 program i need to download report output to excel.
    i did this using OLE concepts code and excel is being downloaded good.
    But problem is all columns data is dumped into First column. But in my ALV i have 20 columns. So i except data in excel sheet to be in 20 columns.
    Below is the OLE code i used
    CREATE OBJECT wa_excel 'EXCEL.APPLICATION'. "Create object for Excel
      SET PROPERTY OF wa_excel  'VISIBLE' = 1. "In background Mode
      CALL METHOD OF wa_excel 'WORKBOOKS' = w_workbook.
      CALL METHOD OF w_workbook 'ADD'. "Create a new Workbook
      SET PROPERTY OF wa_excel 'SheetsInNewWorkbook' = 3. "No of sheets
    * Downloading header details to first sheet
      PERFORM download_sheet TABLES i_final USING 1 'Master Material Details'.
      GET PROPERTY OF wa_excel 'ActiveSheet' = w_worksheet.
    * Protect the first worksheet with a password
      CALL METHOD OF w_worksheet 'PROTECT
        EXPORTING #1 = 'infy@123'.
    * Save the Excel file
      GET PROPERTY OF wa_excel 'ActiveWorkbook' = w_workbook.
      CALL METHOD OF w_workbook 'SAVEAS'
        EXPORTING #1 = p_infile.
      FREE OBJECT: w_worksheet, wa_excel.
    FORM download_sheet TABLES p_tab  USING p_sheet TYPE i   p_name  TYPE string.
      CALL METHOD OF wa_excel 'WORKSHEETS' = w_worksheet
        EXPORTING
        #1 = p_sheet.
      CALL METHOD OF w_worksheet 'ACTIVATE'.
      SET PROPERTY OF w_worksheet 'NAME' = p_name.
      CALL METHOD OF wa_excel 'Range' = w_range
        EXPORTING
        #1 = 'A1'
        #2 = 'D1'.
      CALL METHOD OF w_range 'INTERIOR' = w_int.
      SET PROPERTY OF w_int 'ColorIndex' = 6.
      SET PROPERTY OF w_int 'Pattern' = 1.
    * Initially unlock all the columns( by default all the columns are locked )
      CALL METHOD OF wa_excel 'Columns' = w_columns.
      SET PROPERTY OF w_columns 'Locked' = 0.
    * Locking and formatting first column
      CALL METHOD OF wa_excel 'Columns' = w_columns
       EXPORTING
       #1 = 1.
    * Locking and formatting second column
      CALL METHOD OF wa_excel 'Columns' = w_columns
        EXPORTING
        #2 = 2.
      SET PROPERTY OF w_columns  'Locked' = 2.
      SET PROPERTY OF w_columns  'NumberFormat' = '@'.
    * Export the contents in the internal table to the clipboard
      CALL METHOD cl_gui_frontend_services=>clipboard_export
        IMPORTING
          data                 = p_tab[]
        CHANGING
          rc                   = w_rc
        EXCEPTIONS
          cntl_error           = 1
          error_no_gui         = 2
          not_supported_by_gui = 3
          OTHERS               = 4.
    * Paste the contents in the clipboard to the worksheet
      CALL METHOD OF w_worksheet 'Paste'.
    * Autofit the columns according to the contents
      CALL METHOD OF wa_excel 'Columns' = w_columns.
      CALL METHOD OF w_columns 'AutoFit'.
      FREE OBJECT: w_columns, w_range.
    Please help me if there is any SET Property of WA_EXCEL with which i can handle ALV data into Diffrenet columns.
    Regards,
    jayant.

    hi nabheet,
    we have implemnted this logic and it is workign fine. Bit it takes long time to download data in Excel sheet. Actually it is happening feild by field.
    Please advice any perfomance tuning to this logic.
    Rgs,
    jayant

  • I have a problem in formatting cells in Excel while using OLE method.

    Hi All,
    I have a problem in formatting cells in Excel while using OLE method.
    My requirement is to have certain fields of a cell as text and amount fields should be in number format.
    How to format a cell in Excel in OLE method of downloading data to excel.
    For example I have plant field whose value is 0002 in internal table while coming to excel it is showing as 2 .
    I want that field to be shown as 0002.(text format)
    Material field whose value in internal table is 000000000000000051 is shown as 51 which has to be shown as
    000000000000000051.(text format).
    Amount field should be in number format so that totalling is possible .
    So I need some cells in text format and some in number format.
    Please suggest a sloution.
    Thanks in advance,
    Regards,
    vidyulatha.U

    https://forums.sdn.sap.com/click.jspa?searchID=21931962&messageID=6852860
    hope this helps.

  • Data download to multiple sheets in Excel without using OLE

    Hi,
    Please let me know if it is possible to download data to multiple sheets in excel without using OLE method
    I am in SRM system and the OLE methods are not working
    Please share some sample code or reference links if any
    Thanks
    SekharJ
    Edited by: SekharJ on Sep 8, 2009 8:43 AM

    Here is my code
      LOOP AT it_final INTO wa_final.
        AT FIRST.
          l_ixml = cl_ixml=>create( ).
          l_document = l_ixml->create_document( ).
          l_element_flights  = l_document->create_simple_element(
                      name = 'PO_Details'
                      parent = l_document ).
        ENDAT.
        l_element_airline  = l_document->create_simple_element(
                    name = 'PO'
                    parent = l_element_flights  ).
        l_value = wa_final-object_id.
        l_rc = l_element_airline->set_attribute( name = 'Objectid' value =
                                                             l_value ).
        l_value = wa_final-description.
        l_rc = l_element_airline->set_attribute( name = 'Description' value =
                                                             l_value ).
        l_value = wa_final-number_int.
        l_rc = l_element_airline->set_attribute( name = 'Item' value =
                                                             l_value ).
        l_value = wa_final-description1.
        l_rc = l_element_airline->set_attribute( name = 'Description1' value =
                                                             l_value ).
        l_value = wa_final-quantity.
        l_rc = l_element_airline->set_attribute( name = 'Quantity' value =
                                                             l_value ).
        l_value = wa_final-capex.
        l_rc = l_element_airline->set_attribute( name = 'Capex' value =
                                                             l_value ).
        l_value = wa_final-ser_num.
        l_rc = l_element_airline->set_attribute( name = 'SerialNo' value =
                                                             l_value ).
        l_value = wa_final-plant.
        l_rc = l_element_airline->set_attribute( name = 'Plant' value =
                                                             l_value ).
        l_value = wa_final-loc.
        l_rc = l_element_airline->set_attribute( name = 'Location' value =
                                                             l_value ).
        l_value = wa_final-bundle.
        l_rc = l_element_airline->set_attribute( name = 'Bundle' value =
                                                             l_value ).
      ENDLOOP.
      l_streamfactory = l_ixml->create_stream_factory( ).
      l_ostream = l_streamfactory->create_ostream_itable( table =
    l_xml_table ).
      l_renderer = l_ixml->create_renderer( ostream  = l_ostream
                                            document = l_document ).
      l_rc = l_renderer->render( ).
      l_xml_size = l_ostream->get_num_written_raw( ).
        CALL METHOD cl_gui_frontend_services=>gui_download
          EXPORTING
            bin_filesize = l_xml_size
            filename     = 'c:\temp\flights.xlsx'
            filetype     = 'BIN'
          CHANGING
            data_tab     = l_xml_table
          EXCEPTIONS
            OTHERS       = 24.
        IF sy-subrc <> 0.
          MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                     WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        ENDIF.
    Edited by: SekharJ on Sep 8, 2009 12:04 PM
    Edited by: SekharJ on Sep 8, 2009 12:15 PM

  • Problem in Excel Download

    Hi,
    I am downloading data in an excel file using OLE download from an internal table say t_excel_tab. I need the data to be downloaded into excel in the same order as it was in the internal table t_excel_tab but somehow it is being sorted randomly based on 2 columns.
    Please help me solve this issue.
    Thanks in advance,
    Mathangi

    HI
    GOOD
    CHECK WITH THIS CODE AND USE ACCORDINGLY.
    FUNCTION-POOL ZTEST_OLE. "MESSAGE-ID ..
    TYPE-POOLS: abap.
    EXCEL sheet using OLE automation.
    INCLUDE OLE2INCL.
    DEFINE ole_error.
    IF NOT &1 IS INITIAL.
    MESSAGE e899(v1) WITH 'OLE Error ='(002) &1
    RAISING ole_error.
    ENDIF.
    END-OF-DEFINITION.
    TYPES:
    BEGIN OF ty_line,
    line(4096) TYPE c,
    END OF ty_line.
    CONSTANTS:
    c_tab TYPE x VALUE 9,
    c_bgrw TYPE i VALUE 1,
    c_bgcl TYPE i VALUE 1.
    *For EXCEL operations through ABAP
    DATA:
    w_excel TYPE ole2_object, "Holds the excel application
    w_wbooks TYPE ole2_object, "Holds Work Books
    w_wbook TYPE ole2_object, "Holds Work Book
    w_cell TYPE ole2_object, "Holds Cell
    w_format TYPE ole2_object, "Object for format
    w_font TYPE ole2_object,
    w_sheets TYPE ole2_object, "Holds Active Sheet
    w_range TYPE ole2_object, "To select a range
    *For data processing
    it_line TYPE STANDARD TABLE OF ty_line,
    wa_line TYPE ty_line,
    w_field TYPE ty_line-line,
    w_tab TYPE c.
    FIELD-SYMBOLS:
    <fs_field> TYPE ANY,
    <fs_hex> TYPE ANY.
    *******************TOP Include Ends***********************
    *****************Function Module starts*******************
    FUNCTION ztest_ole_single_table.
    "----"*"Local interface:
    *" IMPORTING
    *" REFERENCE(FILENAME) TYPE RLGRAP-FILENAME
    *" REFERENCE(TABNAME) TYPE CHAR16 OPTIONAL
    *" TABLES
    *" T_DATA
    *" T_HEADING STRUCTURE LINE OPTIONAL
    *" T_FORMATOPT STRUCTURE ZFORMATOPTIONS OPTIONAL
    *" EXCEPTIONS
    *" OLE_ERROR
    *" DATA_EMPTY
    *" CLIPBOARD_EXPORT_ERROR
    DATA:
    file_already_exists TYPE c.
    IF t_data[] IS INITIAL.
    MESSAGE e899(v1) WITH 'No Data in the internal table'(001)
    RAISING data_empty.
    ENDIF.
    ASSIGN w_tab TO <fs_hex> TYPE 'X'.
    <fs_hex> = c_tab.
    REFRESH it_line.
    PERFORM prepare_int_tab TABLES t_data
    t_heading.
    PERFORM create_excel_sheet USING filename
    tabname
    t_data
    CHANGING file_already_exists.
    CHECK NOT t_formatopt[] IS INITIAL.
    PERFORM format_cells TABLES t_formatopt
    USING filename
    file_already_exists.
    ENDFUNCTION.
    ****************Function Module Ends**********************
    ****************F01(Form Include) starts******************
    ***INCLUDE LZTEST_OLEF01 .
    *& Form prepare_int_tab
    text
    --> p1 text
    <-- p2 text
    FORM prepare_int_tab TABLES it_data
    it_heading STRUCTURE line.
    CLEAR wa_line.
    IF NOT it_heading[] IS INITIAL.
    LOOP AT it_heading.
    CONCATENATE wa_line-line
    it_heading-line
    w_tab
    INTO wa_line-line.
    CONDENSE wa_line.
    ENDLOOP.
    APPEND wa_line TO it_line.
    ENDIF.
    LOOP AT it_data.
    CLEAR wa_line.
    DO.
    ASSIGN COMPONENT sy-index OF STRUCTURE it_data TO <fs_field>.
    IF NOT sy-subrc IS INITIAL.
    EXIT.
    ENDIF.
    w_field = <fs_field>.
    CONDENSE w_field.
    CONCATENATE wa_line-line
    w_field
    w_tab
    INTO wa_line-line.
    CONDENSE wa_line.
    ENDDO.
    APPEND wa_line TO it_line.
    ENDLOOP.
    ENDFORM. " prepare_int_tab
    *& Form create_excel_sheet
    text
    --> p1 text
    <-- p2 text
    FORM create_excel_sheet USING p_filename
    p_tabname
    w_data
    CHANGING p_file_already_exists.
    DATA:
    l_cols TYPE i,
    l_rows TYPE i,
    l_name TYPE char16,
    l_rc TYPE sy-subrc,
    l_res TYPE abap_bool,
    l_type TYPE c,
    l_file TYPE string,
    l_from TYPE ole2_object,
    l_to TYPE ole2_object,
    l_entcol TYPE ole2_object.
    CREATE OBJECT w_excel 'Excel.Application'.
    ole_error sy-subrc.
    CALL METHOD OF w_excel 'Workbooks' = w_wbooks.
    ole_error sy-subrc.
    SET PROPERTY OF w_excel 'Visible' = 1.
    ole_error sy-subrc.
    l_file = p_filename.
    CLEAR l_res.
    CALL METHOD cl_gui_frontend_services=>file_exist
    EXPORTING
    file = l_file
    RECEIVING
    result = l_res
    EXCEPTIONS
    cntl_error = 1
    error_no_gui = 2
    wrong_parameter = 3
    OTHERS = 4
    IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    IF l_res IS INITIAL.
    CLEAR p_file_already_exists.
    ELSE.
    p_file_already_exists = 'X'.
    ENDIF.
    IF NOT p_file_already_exists IS INITIAL.
    Open the existing file in case if it exists
    CALL METHOD OF w_wbooks 'Open'
    EXPORTING
    #1 = p_filename.
    ole_error sy-subrc.
    CALL METHOD OF w_excel 'Sheets' = w_sheets.
    ole_error sy-subrc.
    CALL METHOD OF w_sheets 'Add'.
    ole_error sy-subrc.
    GET PROPERTY OF w_excel 'ActiveSheet' = w_wbook.
    ole_error sy-subrc.
    ELSE.
    CALL METHOD OF w_wbooks 'Add'. " = w_wbook.
    ole_error sy-subrc.
    GET PROPERTY OF w_excel 'ActiveSheet' = w_wbook.
    ole_error sy-subrc.
    ENDIF.
    IF NOT p_tabname IS INITIAL.
    SET PROPERTY OF w_wbook 'Name' = p_tabname.
    ole_error sy-subrc.
    ENDIF.
    CALL METHOD OF w_wbook 'Cells' = l_from
    EXPORTING
    #1 = c_bgrw
    #2 = c_bgcl.
    ole_error sy-subrc.
    DESCRIBE FIELD w_data TYPE l_type COMPONENTS l_cols.
    DESCRIBE TABLE it_line LINES l_rows.
    CALL METHOD OF w_wbook 'Cells' = l_to
    EXPORTING
    #1 = l_rows
    #2 = l_cols.
    ole_error sy-subrc.
    CALL METHOD OF w_wbook 'Range' = w_range
    EXPORTING
    #1 = l_from
    #2 = l_to.
    ole_error sy-subrc.
    CALL METHOD cl_gui_frontend_services=>clipboard_export
    IMPORTING
    data = it_line
    CHANGING
    rc = l_rc
    EXCEPTIONS
    cntl_error = 1
    error_no_gui = 2
    OTHERS = 3
    IF sy-subrc <> 0
    OR NOT l_rc IS INITIAL.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
    RAISING clipboard_export_error.
    ENDIF.
    CALL METHOD OF w_range 'Select'.
    ole_error sy-subrc.
    CALL METHOD OF w_wbook 'Paste'.
    ole_error sy-subrc.
    WHILE l_cols GT 0.
    l_rows = 1.
    CALL METHOD OF w_excel 'Columns' = w_cell
    EXPORTING
    #1 = l_cols.
    ole_error sy-subrc.
    CALL METHOD OF w_cell 'EntireColumn' = l_entcol.
    ole_error sy-subrc.
    l_cols = l_cols - 1.
    CALL METHOD OF l_entcol 'Autofit'.
    ole_error sy-subrc.
    ENDWHILE.
    ENDFORM. " create_excel_sheet
    *& Form format_cells
    text
    -->P_FILENAME text
    -->P_FILE_ALREADY_EXISTS text
    FORM format_cells TABLES it_formatopt STRUCTURE zformatoptions
    USING p_filename TYPE rlgrap-filename
    p_file_already_exists TYPE c.
    DATA:
    l_row TYPE i,
    l_col TYPE i,
    l_entcol TYPE ole2_object,
    l_cols TYPE ole2_object,
    l_comment TYPE ole2_object.
    LOOP AT it_formatopt.
    CLEAR: l_row, l_col.
    l_row = it_formatopt-row.
    l_col = it_formatopt-col.
    CALL METHOD OF w_wbook 'Cells' = w_cell
    EXPORTING
    #1 = l_row
    #2 = l_col.
    ole_error sy-subrc.
    IF NOT it_formatopt-bold IS INITIAL.
    CALL METHOD OF w_cell 'Font' = w_font.
    ole_error sy-subrc.
    SET PROPERTY OF w_font 'Bold' = 1.
    ole_error sy-subrc.
    CALL METHOD OF w_excel 'Columns' = l_cols
    EXPORTING
    #1 = l_col.
    ole_error sy-subrc.
    CALL METHOD OF l_cols 'EntireColumn' = l_entcol.
    ole_error sy-subrc.
    CALL METHOD OF l_entcol 'Autofit'.
    ole_error sy-subrc.
    ENDIF.
    IF NOT it_formatopt-color IS INITIAL.
    CALL METHOD OF w_cell 'Interior' = w_format.
    ole_error sy-subrc.
    SET PROPERTY OF w_format 'ColorIndex' = it_formatopt-color.
    ole_error sy-subrc.
    CALL METHOD OF w_excel 'Columns' = l_cols
    EXPORTING
    #1 = l_col.
    ole_error sy-subrc.
    CALL METHOD OF l_cols 'EntireColumn' = l_entcol.
    ole_error sy-subrc.
    CALL METHOD OF l_entcol 'Autofit'.
    ole_error sy-subrc.
    ENDIF.
    IF NOT it_formatopt-vert IS INITIAL.
    SET PROPERTY OF w_cell 'Orientation' = it_formatopt-vert.
    ole_error sy-subrc.
    CALL METHOD OF w_excel 'Columns' = l_cols
    EXPORTING
    #1 = l_col.
    ole_error sy-subrc.
    CALL METHOD OF l_cols 'EntireColumn' = l_entcol.
    ole_error sy-subrc.
    CALL METHOD OF l_entcol 'Autofit'.
    ole_error sy-subrc.
    ENDIF.
    IF NOT it_formatopt-comments IS INITIAL.
    CALL METHOD OF w_excel 'Range' = w_range
    EXPORTING
    #1 = l_row
    #2 = l_col.
    ole_error sy-subrc.
    CALL METHOD OF w_range 'Select'.
    ole_error sy-subrc.
    CALL METHOD OF w_cell 'AddComment' = l_comment.
    ole_error sy-subrc.
    CALL METHOD OF l_comment 'Text'
    EXPORTING
    #1 = it_formatopt-comments.
    ole_error sy-subrc.
    ENDIF.
    ENDLOOP.
    PERFORM save_and_close USING p_filename
    p_file_already_exists.
    ENDFORM. " format_cells
    *& Form save_and_close
    text
    -->P_P_FILENAME text
    -->P_P_FILE_ALREADY_EXISTS text
    FORM save_and_close USING p_filename
    p_file_already_exists.
    IF p_file_already_exists IS INITIAL.
    CALL METHOD OF w_wbook 'Saveas'
    EXPORTING
    #1 = p_filename.
    ole_error sy-subrc.
    ELSE.
    CALL METHOD OF w_excel 'ActiveWorkbook' = w_wbooks.
    ole_error sy-subrc.
    CALL METHOD OF w_wbooks 'Save'.
    ole_error sy-subrc.
    ENDIF.
    CALL METHOD OF w_wbooks 'Close'.
    ole_error sy-subrc.
    ENDFORM. " save_and_close
    **************Form Include Ends***************************
    *********************Test Progam**************************
    REPORT ztest_ole.
    TABLES mara.
    SELECT-OPTIONS:
    s_matnr FOR mara-matnr.
    PARAMETERS:
    p_file TYPE rlgrap-filename,
    p_tabnm TYPE char16.
    DATA:
    BEGIN OF it_mara OCCURS 1,
    matnr TYPE mara-matnr, "Material No.
    mtart TYPE mara-mtart, "Material Type
    matkl TYPE mara-matkl, "Material Group
    groes TYPE mara-groes, "Size/Dimension
    END OF it_mara,
    it_heading TYPE STANDARD TABLE OF line,
    wa_heading TYPE line,
    it_formatopt TYPE STANDARD TABLE OF zformatoptions,
    wa_format TYPE zformatoptions,
    l_col TYPE zformatoptions-col.
    START-OF-SELECTION.
    SELECT matnr
    mtart
    matkl
    groes
    FROM mara
    UP TO 100 ROWS
    INTO TABLE it_mara.
    wa_heading-line = 'Material No.'. APPEND wa_heading TO it_heading.
    wa_heading-line = 'Material Type'. APPEND wa_heading TO it_heading.
    wa_heading-line = 'Material Group'. APPEND wa_heading TO it_heading.
    wa_heading-line = 'Size/Dimension'. APPEND wa_heading TO it_heading.
    DO 4 TIMES.
    CLEAR wa_format.
    wa_format-row = 1.
    wa_format-col = l_col + 1.
    l_col = l_col + 1.
    wa_format-bold = 'X'.
    wa_format-color = '6'.
    wa_format-vert = 45.
    wa_format-comments = 'This is a heading'.
    APPEND wa_format TO it_formatopt.
    ENDDO.
    CALL FUNCTION 'ZTEST_OLE_SINGLE_TABLE'
    EXPORTING
    filename = p_file
    tabname = p_tabnm
    TABLES
    t_data = it_mara
    t_heading = it_heading
    t_formatopt = it_formatopt
    EXCEPTIONS
    ole_error = 1
    data_empty = 2
    clipboard_export_error = 3
    OTHERS = 4.
    IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
    PERFORM get_file CHANGING p_file.
    *& Form get_file
    text
    <--P_P_FILE text
    FORM get_file CHANGING p_file.
    DATA:
    l_file TYPE string,
    l_path TYPE string,
    l_fpath TYPE string.
    CALL METHOD cl_gui_frontend_services=>file_save_dialog
    CHANGING
    filename = l_file
    path = l_path
    fullpath = l_fpath
    EXCEPTIONS
    cntl_error = 1
    error_no_gui = 2
    OTHERS = 3
    IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    p_file = l_fpath.
    ENDFORM. " get_file
    THANKS
    MRUTYUN

  • Is it possible to create Excel Sheet using OLE automation in App server

    Hi,
       Is it possible to create Excel Sheet using OLE automation in Application server(Open Dataset)
    Thanks in advance...

    Unless your application server is on Windows OS, or it is connected to a Windows server by RFC. What is the requirement exactly, I don't understand?

  • Regading Excel Creation using OLE

    hi friends,
    i got a new requirement where i have to create the Excel document using OLE. one more thing is some cells has to be filled with some colour and in some cells the text has to come in Vertical manner, this text is used for Header purpose.
    please help me urgently...
    Suitable Answers will get more points..........

    Hello,
    Also take a look at this code
    *& Report  ZKRIS_OLE3_PALETTE
    *& Displays the full OLE color range in excel
    REPORT  ZKRIS_OLE3_PALETTE.
    TYPE-POOLS ole2 .
    DATA:  count TYPE i,
           count_real TYPE i,
           application TYPE ole2_object,
           workbook TYPE ole2_object,
           excel     TYPE ole2_object,
           sheet TYPE ole2_object,
           cells TYPE ole2_object.
    CONSTANTS: row_max TYPE i VALUE 256. " change to 16384 for excel 2007
    DATA index TYPE i.
    DATA:
          h_cell        TYPE ole2_object,        " cell
          h_f           TYPE ole2_object,        " font
          h_int         TYPE ole2_object,
          h_width       TYPE ole2_object,
          h_columns     TYPE ole2_object,
          h_rows        TYPE ole2_object,
          h_font        TYPE ole2_object,
          h_entirecol   TYPE ole2_object.
    DATA: h_range       TYPE ole2_object.
    DATA: h_merge       TYPE ole2_object.
    CREATE OBJECT excel 'EXCEL.APPLICATION'.
    IF sy-subrc NE 0.
      WRITE: / 'No EXCEL creation possible'.
      STOP.
    ENDIF.
    SET PROPERTY OF excel 'DisplayAlerts' = 0.
    CALL METHOD OF excel 'WORKBOOKS' = workbook .
    SET PROPERTY OF excel 'VISIBLE' = 1.
    * creating workbook
    SET PROPERTY OF excel 'SheetsInNewWorkbook' = 1.
    CALL METHOD OF workbook 'ADD'.
    CALL METHOD OF excel 'WORKSHEETS' = sheet
      EXPORTING
        #1 = 1.
    SET PROPERTY OF sheet 'NAME' = 'Color Palette'.
    CALL METHOD OF sheet 'ACTIVATE'.
    DATA: col TYPE i VALUE 1,
    row TYPE i VALUE 2,
    col1 TYPE i VALUE 2,
    col_real TYPE i VALUE 1.
    row = 1.
    col = 3.
    CALL METHOD OF excel 'Cells' = h_cell
      EXPORTING
        #1 = row
        #2 = col.
    SET PROPERTY OF h_cell 'Value' = 'No.'.
    col = col + 1.
    CALL METHOD OF excel 'Cells' = h_cell
      EXPORTING
        #1 = row
        #2 = col.
    SET PROPERTY OF h_cell 'Value' = 'Background'.
    col = col + 1.
    CALL METHOD OF excel 'Cells' = h_cell
      EXPORTING
        #1 = row
        #2 = col.
    SET PROPERTY OF h_cell 'Value' = 'Foreground with white background'.
    col = col + 1.
    CALL METHOD OF excel 'Cells' = h_cell
      EXPORTING
        #1 = row
        #2 = col.
    SET PROPERTY OF h_cell 'Value' = 'Foreground with black background'.
    CALL METHOD OF excel 'Rows' = h_rows
      EXPORTING
        #1 = '2:2'.
    SET PROPERTY OF h_rows 'WrapText' = 1.
    col = 9.
    CALL METHOD OF excel 'Cells' = h_cell
      EXPORTING
        #1 = row
        #2 = col.
    SET PROPERTY OF h_cell 'Value' = 'No.'.
    col = col + 1.
    CALL METHOD OF excel 'Cells' = h_cell
      EXPORTING
        #1 = row
        #2 = col.
    SET PROPERTY OF h_cell 'Value' = 'Background'.
    col = col + 1.
    CALL METHOD OF excel 'Cells' = h_cell
      EXPORTING
        #1 = row
        #2 = col.
    SET PROPERTY OF h_cell 'Value' = 'Foreground with white background'.
    SET PROPERTY OF h_cell 'Bold' = 1.
    col = col + 1.
    CALL METHOD OF excel 'Cells' = h_cell
      EXPORTING
        #1 = row
        #2 = col.
    SET PROPERTY OF h_cell 'Value' = 'Foreground with black background'.
    CALL METHOD OF excel 'Rows' = h_rows
      EXPORTING
        #1 = '1:1'.
    SET PROPERTY OF h_rows 'WrapText' = 1.
    GET PROPERTY OF h_rows 'Font' = h_font.
    SET PROPERTY OF h_font 'Bold' = 1.
    count = 1.
    count_real = count.
    row = 2.
    col = 3.
    DO 56 TIMES.
      PERFORM write_num_and_color.
    ENDDO.
    * autofit
    CALL METHOD OF excel 'Columns' = h_columns
      EXPORTING
        #1 = 'C:L'.
    GET PROPERTY OF h_columns 'EntireColumn' = h_entirecol.
    SET PROPERTY OF h_entirecol 'Autofit' = 1.
    * write palette on lhs
    *range
    CALL METHOD OF excel 'Range' = h_range
      EXPORTING
        #1 = 'A2'
        #2 = 'A20'.
    CALL METHOD OF h_range 'Merge' = h_merge .
    CALL METHOD OF excel 'Cells' = h_cell
      EXPORTING
        #1 = 2
        #2 = 1.
    SET PROPERTY OF h_cell 'Value' = 'Palette'.
    SET PROPERTY OF h_cell 'Orientation' = 90.         "angled.
    SET PROPERTY OF h_cell 'HorizontalAlignment' = 3.  "center align
    GET PROPERTY OF h_cell 'Font'    = h_f.
    SET PROPERTY OF h_f 'Bold' = 1.                    "bold
    SET PROPERTY OF h_f 'Name' = 'Comic Sans MS'.
    SET PROPERTY OF h_f 'Size' = '14'.
    SET PROPERTY OF h_cell 'VerticalAlignment' = 2.  "center align
    * autofit
    CALL METHOD OF excel 'Columns' = h_columns
      EXPORTING
        #1 = 'A:A'.
    GET PROPERTY OF h_columns 'EntireColumn' = h_entirecol.
    SET PROPERTY OF h_columns 'ColumnWidth' = 4.
    *&      Form  write_num_and_color
    *       text
    FORM write_num_and_color.
      index = row_max * ( row - 1 ) + col.
      CALL METHOD OF sheet 'Cells' = cells
        EXPORTING
          #1 = index.
      SET PROPERTY OF cells 'Value' = count_real.
      col = col + 1.
      CALL METHOD OF excel 'Cells' = h_cell
        EXPORTING
          #1 = row
          #2 = col.
      GET PROPERTY OF h_cell 'Interior'   = h_int.
      SET PROPERTY OF h_int  'ColorIndex' = count_real.
      col = col + 1.
      CALL METHOD OF excel 'Cells' = h_cell
        EXPORTING
          #1 = row
          #2 = col.
      SET PROPERTY OF h_cell 'Value' = 'Sample Text'.
      GET PROPERTY OF h_cell 'Font'    = h_f.
      SET PROPERTY OF h_f 'ColorIndex' = count_real.
      col = col + 1.
      CALL METHOD OF excel 'Cells' = h_cell
        EXPORTING
          #1 = row
          #2 = col.
      GET PROPERTY OF h_cell 'Interior'   = h_int.
      SET PROPERTY OF h_int  'ColorIndex' = 1.
      SET PROPERTY OF h_cell 'Value' = 'Sample Text'.
      GET PROPERTY OF h_cell 'Font'    = h_f.
      SET PROPERTY OF h_f 'ColorIndex' = count_real.
      row = row + 1.
      col = col - 3.
      count = count + 1.
      IF count = 29.
        count = 1.
        row = 2.
        col = col + 6.
      ENDIF.
      count_real = count_real + 1.
    ENDFORM.                    "write_num_and_color

  • Call Excel SpreadSheet using OLE and set format = text

    Hi All,
    I am working on an object, where I need to call Excel SpreadSheet using OLE.
    In SpreadSheet, I need to show data as text (Without Excel Internal Modifications).
    i.e
    if i pass 03/2007 as month in excel, it should show  01/2007 not jan-07.
    I am trying to use the code as below.
    call method of cell 'SET_FORMAT' = text.
    set property of text 'CATEGORY' = 4.
    this code is not giving me desired output.
    Is there any other method i can call? or property I can set?
    can somebody pls send me a document with list of all formattiong methods and properties. I will really appreciate the help.
    Regards,
    Hardik

    Hi, you should concatenate the character ( ' ) into your text, example
    CONCATENATE '''' text INTO text.
    Then print the variable Text into excel and you will see the format as Text,
    Thanks and regards.
    David Carballido
    PD: Sry for my bad English

  • To upload excel file directly to the application server using OLE concept

    hi experts
    i have done a coding in OLE to download excel with graph to presentation server, is it possible to upload excel with graph directly to the application server  , the excel should have graph while downloading to presentation server fom app server.
    Moderator message - duplicate post locked
    Edited by: Rob Burbank on Jun 25, 2009 9:49 AM

    HI,
    have a look at tcode cg3z and then FM 'C13Z_FILE_UPLOAD_ASCII'.
    What you can do is, first create the file on presentation server using OLE automation, and then using this FM, write the file to Application server

  • Issue in Background mode -Excel downloading using typepool OLE2

    Hi ,
    I am working a report using OLE type pool.
    Based on conditions the colors should display in excel sheet. As its displaying the colors correctly.
    Issue:
    1) How we will execute the OLE download in back ground
    as i am using the below code as visible '0', if Visible '1'. the file is executing in fore ground and viewing the records.
    SET PROPERTY OF H_EXCEL 'Visible' = 0 "in background
    Issue: But again there is a wait until the excel is downloaded completely. How can we avoid it is ,If we run in backgroundu2026.it doesn't create the file. What could be done such that user opts for excel output and should not wait on screen.
    Please let me know any option OLE to get the file in background with out waiting in selection screen.

    Hi samruth,
    The function of ABAP/4 OLE Automation Controller is to connect to  Desktop applications supporting OLE2 that can be thus be called from R/3.
    In background, there is no Desktop.
    Thats it.
    There is this really interesting [abap2xlsx|http://wiki.sdn.sap.com/wiki/display/ABAP/abap2xlsx] project. If you are prepared to forget OLE then this is the way to go.
    Regards,
    Clemens

  • Problem with header download using GUI_DOWNLOAD

    Hi folks,
    Iam facing a particular problem while downloading an internal table to excel file using GUI_DOWNLOAD and file type as 'DBF'.
    Once i download the file, iam getting an automatic header with contents as "F1, F2, F3,...." for all the columns. But, i want to put my own header there. Is there any way out ?
    Thanks and Regards,
    Vijay.

    hi,
    may be this code will be helpful to u
    Just take one field in header(internal table) of type c. and push all the field headings into it.
    and give that internal table to fieldnames it will resolve the problem.
    DATA:BEGIN OF HEADER OCCURS 0,
          F1(30) TYPE C ,
         END OF HEADER.
    DATA:BEGIN OF ITEM OCCURS 0,
           IT1(30) TYPE C,
           IT2(3) TYPE C,
           IT3(4) TYPE C,
         END OF ITEM.
       HEADER-F1 = 'NAME'.
       APPEND HEADER.
       CLEAR HEADER.
       HEADER-F1 = 'AGE'.
       APPEND HEADER.
       CLEAR HEADER.
       HEADER-F1  = 'STAT'.
       APPEND HEADER.
       CLEAR HEADER.
    ITEM-IT1 = 'MANOHAR'.
    ITEM-IT2 = '124'.
    ITEM-IT3 = 'T'.
    APPEND ITEM.
    CLEAR ITEM.
    ITEM-IT1 = 'SAI'.
    ITEM-IT2 = '24'.
    ITEM-IT3 = 'T'.
    APPEND ITEM.
    CLEAR ITEM.
    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
        filename                        = 'C:\FILE13.XLS'
       FILETYPE                        = 'DBF'
      tables
        data_tab                        = ITEM
        FIELDNAMES                      = HEADER.
    regards,
    manohar.

  • Setting the aixs minimum in excel chart using OLE.

    Hi All,
              The problem am facing is that say if all the values in the chart data range is high  then excel adjusts itself so that the axis minimum doesn't start from zero. But i need the axis to always start from zero. How do i set this using OLE?

    Hi
    Here is ur expected coding...
    REPORT ZCREATEEXCEL.
    TYPE-POOLS OLE2.
    DATA: EXCEL TYPE OLE2_OBJECT,
    WORKBOOKS TYPE OLE2_OBJECT,
    WORKBOOK TYPE OLE2_OBJECT.
    DATA: FILENAME LIKE RLGRAP-FILENAME.
    START THE EXCEL APPLICATION
    CREATE OBJECT EXCEL 'EXCEL.APPLICATION'.
    PERFORM ERR_HDL.
    PUT EXCEL IN FRONT
    SET PROPERTY OF EXCEL 'VISIBLE' = 1.
    PERFORM ERR_HDL.
    INFORM USER OF THE CURRENT STATUS
    CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
    EXPORTING
    PERCENTAGE = 0
    TEXT = TEXT-I08
    EXCEPTIONS
    OTHERS = 1.
    CREATE AN EXCEL WORKBOOK OBJECT
    CALL METHOD OF EXCEL 'WORKBOOKS' = WORKBOOKS.
    PERFORM ERR_HDL.
    CALL METHOD OF WORKBOOKS 'ADD' = WORKBOOK.
    PERFORM ERR_HDL.
    EXCEL FILENAME
    CONCATENATE SY-REPID '_' SY-DATUM6(2) '_' SY-DATUM4(2) '_'
    SY-DATUM(4) '_' SY-UZEIT '.XLS' INTO FILENAME.
    CALL METHOD OF WORKBOOK 'SAVEAS' EXPORTING #1 = FILENAME.
    FORM ERR_HDL.
    IF SY-SUBRC <> 0.
    WRITE: / 'OLE ERROR: RETURN CODE ='(I10), SY-SUBRC.
    STOP.
    ENDIF.
    ENDFORM.
    Reward if usefull

  • Create Excel sheet using OLE

    Hi All,
           Can any one help me to create an multiple excel sheet in an work book using OLE. I want to create more than 3 sheets in excel, which is default sheets in excel when we one excel.

    Hi,
    Check the below sample code.
    Here I'm downloading the same table twice into 2 different sheets for example purpose.
    TYPE-POOLS ole2.
    DATA: wf_cell_from  TYPE ole2_object,
          wf_cell_from1 TYPE ole2_object,
          wf_cell_to    TYPE ole2_object,
          wf_cell_to1   TYPE ole2_object,
          wf_excel      TYPE ole2_object,   " Excel object
          wf_mapl       TYPE ole2_object,   " list of workbooks
          wf_map        TYPE ole2_object,   " workbook
          wf_worksheet  TYPE ole2_object,   " Worksheet
          wf_cell       TYPE ole2_object,   " Cell Range
          wf_cell1      TYPE ole2_object,
          wf_range      TYPE ole2_object,   " Range of cells to be formatted
          wf_range2     TYPE ole2_object,
          wf_column1    TYPE ole2_object.   " Column to be Autofit
    DATA: BEGIN OF t_hex,
          l_tab TYPE x,
          END OF t_hex.
    DATA: wf_deli(1) TYPE c,            "delimiter
          wf_action TYPE i,
          wf_file TYPE string,
          wf_path TYPE string,
          wf_fullpath TYPE string.
    TYPES: t_data1(1500) TYPE c,
           int_ty TYPE TABLE OF t_data1. "line type internal table
    *All the data was prepared as line type internal tables for faster
    *download
    DATA: int_matl  TYPE int_ty ,
          int_matl1 TYPE int_ty ,
          wa_matl   TYPE t_data1.
    TYPES: BEGIN OF ty_mara,
           matnr TYPE matnr,
           mtart TYPE mtart,
           matkl TYPE matkl,
           meins TYPE meins,
           END OF ty_mara.
    DATA: int_mara TYPE STANDARD TABLE OF ty_mara,
          wa_mara TYPE ty_mara.
    FIELD-SYMBOLS: <fs> .
    DATA: wc_sheets LIKE sy-index.  "no.of sheets
    DATA: it_tabemp TYPE filetable,
          gd_subrcemp TYPE i.
    CONSTANTS wl_c09(2) TYPE n VALUE 09.
    CLEAR wc_sheets.
    DEFINE ole_check_error.
      if &1 ne 0.
        message e001(zz) with &1.
        exit.
      endif.
    END-OF-DEFINITION.
    SELECTION-SCREEN BEGIN OF BLOCK block1 WITH FRAME TITLE text-001.
    PARAMETERS: p_file   LIKE rlgrap-filename.
    SELECTION-SCREEN END OF BLOCK block1.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
      REFRESH: it_tabemp.
      CALL METHOD cl_gui_frontend_services=>file_save_dialog
        EXPORTING
          window_title         = 'Select File'
    *      default_extension    = 'xls'
          default_file_name    = 'Material Details'
    *      with_encoding        =
          file_filter          = '*.xls'
          initial_directory    = 'C:\'
          prompt_on_overwrite  = ' '
        CHANGING
          filename             = wf_file
          path                 = wf_path
          fullpath             = wf_fullpath
          user_action          = wf_action
    *      file_encoding        =
        EXCEPTIONS
          cntl_error           = 1
          error_no_gui         = 2
          not_supported_by_gui = 3
          OTHERS               = 4
      IF sy-subrc <> 0.
    *   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      IF wf_action EQ 9.
        MESSAGE 'No File have been Selected' TYPE 'S'.
      ELSE.
        p_file = wf_fullpath.
        PERFORM create_excel.
      ENDIF.
    *&      Form  create_excel
    *       text
    FORM create_excel.
      LOOP AT it_tabemp INTO p_file.
      ENDLOOP.
    * START THE EXCEL APPLICATION
      CREATE OBJECT wf_excel 'EXCEL.APPLICATION'.
      PERFORM err_hdl.
    * PUT EXCEL IN FRONT
      SET PROPERTY OF wf_excel  'VISIBLE' = 1.
      PERFORM err_hdl.
    * CREATE AN EXCEL WORKBOOK OBJECT
      CALL METHOD OF wf_excel 'WORKBOOKS' = wf_mapl.
      PERFORM err_hdl.
      SET PROPERTY OF wf_excel 'SheetsInNewWorkbook' = 3. "no of sheets
      PERFORM err_hdl.
      CALL METHOD OF wf_mapl 'ADD' = wf_map.
      PERFORM err_hdl.
    *Assign the Delimiter to field  symbol.
      ASSIGN wf_deli TO <fs> TYPE 'X'.
      t_hex-l_tab = wl_c09.
      <fs> = t_hex-l_tab.
      CLEAR int_matl.
      REFRESH int_matl.
      SELECT matnr
           mtart
           matkl
           meins
          FROM mara
          INTO CORRESPONDING FIELDS OF TABLE int_mara.
    *first the headings will be displayed  in the excel sheet
      CONCATENATE 'Material Number'
      'Material type'
      'Material Group'
      'Base Unit of Measure'
      INTO wa_matl
      SEPARATED BY wf_deli.
      APPEND wa_matl TO int_matl.
      LOOP AT int_mara INTO wa_mara.
        CONCATENATE wa_mara-matnr
                    wa_mara-mtart
                    wa_mara-matkl
                    wa_mara-meins
                    INTO wa_matl
                    SEPARATED BY wf_deli.
        APPEND wa_matl TO int_matl.
        CLEAR wa_matl.
      ENDLOOP.
    *Copyng thae same contents to another table to display in
    *new sheet
      MOVE int_matl TO int_matl1.
      PERFORM f_material_details
      TABLES int_matl
      USING  1.
      PERFORM f_material_details
      TABLES int_matl
      USING  2.
      GET PROPERTY OF wf_excel 'ActiveSheet' = wf_map.
      GET PROPERTY OF wf_excel 'ActiveWorkbook' = wf_mapl.
      CALL FUNCTION 'FLUSH'
        EXCEPTIONS
          cntl_system_error = 1
          cntl_error        = 2
          OTHERS            = 3.
      IF sy-subrc = 0.
        CALL METHOD OF wf_map 'SAVEAS'
          EXPORTING #1 = p_file.
      ENDIF.
      CALL METHOD OF wf_mapl 'CLOSE'.
      CALL METHOD OF wf_excel 'QUIT'.
      FREE OBJECT wf_mapl.
      FREE OBJECT wf_map.
      FREE OBJECT wf_excel.
    ENDFORM.                    "create_excel
    *&      Form  ERR_HDL
    *       text
    FORM err_hdl.
      IF sy-subrc <> 0.
        WRITE: / 'OLE ERROR: RETURN CODE ='(i10), sy-subrc.
        STOP.
      ENDIF.
    ENDFORM.                    "ERR_HDL
    *-- End of Program
    *&      Form  f_material_details
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM f_material_details
       TABLES lint_matl
      USING l_sheet_no TYPE i.
      DATA: lv_lines TYPE i,
            lv_sheet_name(50) TYPE c.
      wc_sheets = l_sheet_no.
      CASE l_sheet_no.
        WHEN 1.
          lv_sheet_name = 'Material_sheet1'.
        WHEN 2.
          lv_sheet_name = 'Material_sheet2'.
      ENDCASE.
    *-- activating the worksheet and giving a  name to it
      CALL METHOD OF wf_excel 'WORKSHEETS' = wf_worksheet
        EXPORTING
        #1 = wc_sheets.
      CALL METHOD OF wf_worksheet 'ACTIVATE'.
      SET PROPERTY OF wf_worksheet 'NAME' = lv_sheet_name.
    *--formatting the cells
      CALL METHOD OF wf_excel 'Cells' = wf_cell_from
        EXPORTING
        #1 = 1
        #2 = 1.
      DESCRIBE TABLE lint_matl LINES lv_lines.
      CALL METHOD OF wf_excel 'Cells' = wf_cell_to
        EXPORTING
        #1 = lv_lines
        #2 = 4.
    *--range of cells to be formatted (in this case 1 to 4)
      CALL METHOD OF wf_excel 'Range' = wf_cell
        EXPORTING
        #1 = wf_cell_from
        #2 = wf_cell_to.
    *--formatting the cells
      CALL METHOD OF wf_excel 'Cells' = wf_cell_from1
        EXPORTING
        #1 = 1
        #2 = 1.
      DESCRIBE TABLE lint_matl LINES lv_lines.
      CALL METHOD OF wf_excel 'Cells' = wf_cell_to1
        EXPORTING
        #1 = lv_lines
        #2 = 1.
      CALL METHOD OF wf_excel 'Range' = wf_cell1  " Cell range for first
                                                  " column(Material)
        EXPORTING
        #1 = wf_cell_from1
        #2 = wf_cell_to1.
      SET PROPERTY OF wf_cell1 'NumberFormat' = '@' . "To disply zeros
      "in Material number
      DATA l_rc TYPE i.
    *DATA download into excel first sheet
      CALL METHOD cl_gui_frontend_services=>clipboard_export
        IMPORTING
          data         = lint_matl[]
        CHANGING
          rc           = l_rc
        EXCEPTIONS
          cntl_error   = 1
          error_no_gui = 2
          OTHERS       = 4.
      CALL METHOD OF wf_worksheet 'Paste'.
      CALL METHOD OF wf_excel 'Columns' = wf_column1.
      CALL METHOD OF wf_column1 'Autofit'.
      FREE OBJECT wf_column1.
    ENDFORM.                    " f_material_details
    Regards,
    Manoj Kumar P
    Edited by: Manoj Kumar on Mar 5, 2009 11:25 AM

  • Problem with Excel Download

    Hi There,
    Were upgradding to version 700 (ECC 2005) and we have a problem when we download to excel.
    When program (customer) is run (in foreground) we get an dump when we try to download to excel using the MS_EXCEL_OLE_STANDARD_DAT Function Module. it seems to have a problem when it gets to the; call method cl_gui_frontend_services => file_exist
    SAP kernal 700
    SAP database 700
    SAP Gui 640
    Any thought on the problem ?
    Thanks

    Hi Santosh,
    I cant change the code because it's SAP standard (I would njeed to find an OSS note and there doesnt seems to be one there) the SAP Standard incluse is LSLPCF02 and the code is as follows:
    DATA: fname type string,
            result type abap_bool.
      fname = file_name.
      CALL METHOD cl_gui_frontend_services=>file_exist
        EXPORTING
          file            = fname
        receiving
          result          = result
        EXCEPTIONS
          others          = 0.
      call method cl_gui_cfw=>flush.
      IF result = abap_false.
        RAISE file_not_exist.
      ENDIF.
    This seems to be the same, only difference is the way i_result is declared ??
    Thanks

Maybe you are looking for

  • Text in mail window is jumbled like chinese

    After leaving mail running for a while I will get text displayed in jumbled type like its chinese, I have plenty of memory 1 gig. after restart of program this will go away and display fine. It's really frustrating sometimes.

  • Will the ipad 3rd gen be able to get iOS 7?

    I keep finding mixed anwsers all I want to know is if I will be able to get iOS 7 on my ipad 3rd gen

  • ORA-02042: too many distributed transactions

    1. I have been working on a portal application for several weeks. 2. Portal is installed in 1 instance and my data is in another instance. 3. I've had no ora-02042 problems in the devt environment set up that way. 4. I've recently migrated the applic

  • Mozilla Thunderbird crashes

    Anybody having trouble with Mozilla Thunderbird?  All of a sudden my program crashes every time I try to open it.  Input would be greatly appreciated. Thanks to all!~ " .. Good Art Won't (Necessarily) Match Your Sofa .." [X61 Think Pad Tablet Model 7

  • Aperture 3.1.3. 3.2. checking library  constantly

    Hi there, since i updated from 3.1.3. to 3.2. every time i start aperture the library will be checked and updated. How can i turn it off? Thanks. Regards -s