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

Similar Messages

  • How can I disenable the EXCEL field format when use ALV download to excel ?

    Dear friends,
         I have a problem with the ALV download to EXCEL. One field Value in ALV is like u2018-abcdeu2026u2019.the character u201C-u201Cis the first   position  in field value.when I download  the value to EXCEL,the field value u2018-abcdeu2026u2019 changed u2018=-abcdeu2026u2019 in EXCEL.how can I remove u2018=u2019 in EXCEL when I down to excel used ALV.
    I add a space in u2018  -abcdeu2026u2019,So this value can be download to Excel .
    Have you any solve method?
    User does not use excel logo button to download.
    User use Local fileu2026 button to download
    Thanks
    Sun

    add a single quote to the beginning of the field.
    like:  '-abcde
    in excel it will be shown as : -abcde

  • 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 .

  • ALV download to excel inquiry

    Hi,
    I have a problem with regards to the ALV download to excel.  I have an ALV grid with 40 columns and i need to download the output to an excel file.  But after downloading the ALV output, i noticed that some columns are already on the next line. i need to have all columns to be in the same line.  Does anyone have an idea how to prevent columns to be printed in the next line?
    Thanks in advance!
    Kind regards,
    Merriam

    Looks like Note 855314 has a workaround ... my be more.
    Of course (yuk!), write you own download.
    Best!
    Jim

  • ALV downloaded to EXCEL -using standard button-how to modify the EXCEL ???

    hey guys,
      i have developed an ALV (with dynamic itnernal table,with HTML top of page,using FMs)
    Now ,i ahd problems with downlaod to excel(which i partly overcame by using &XXL fcode button instead of other 'donwload to excel button' )..
    now the data is downloading to excel fne..
    but i need to customise the EXCEL with HEADING (with bold letters in colour).. and also adding a line in ALV COLOUMN HEADINGS part of EXCEL...

    Hi,
    Kindly go through the below link to download a file in Excel format from ALV,
    https://www.sdn.sap.com/irj/scn/wiki?path=/display/snippets/alv%252bgrid%252bdisplay%252bwith%252bcheckbox%252bto%252bprocess%252bselected%252brecords%252bat%252bruntime
    Note:  In the function module ->GUI_DOWNLOAD
    You have to give Field Separator as 'X'.
    Hope it helps You.
    Regards
    Mansi

  • Need to load large data set from Oracle table onto desktop using ODBC

    I don't have TOAD nor any other tool for querying the database.  I'm wondering how I can load a large data set from an Oracle table onto my desktop using Excel or Access or some other tool using ODBC or not using ODBC if that's possible.  I need results to be in a .csv file or something similar. Speed is what is important here.  I'm looking to load more than 1 million but less than 10 million records at once.   Thanks.

    hillelhalevi wrote:
    I don't have TOAD nor any other tool for querying the database.  I'm wondering how I can load a large data set from an Oracle table onto my desktop using Excel or Access or some other tool using ODBC or not using ODBC if that's possible.  I need results to be in a .csv file or something similar. Speed is what is important here.  I'm looking to load more than 1 million but less than 10 million records at once.   Thanks.
    Use Oracle's free Sql Developer
    http://www.oracle.com/technetwork/developer-tools/sql-developer/downloads/index.html
    You can just issue a query like this
    SELECT /*csv*/ * FROM SCOTT.EMP
    Then just save the results to a file
    See this article by Jeff Smith for other options
    http://www.thatjeffsmith.com/archive/2012/05/formatting-query-results-to-csv-in-oracle-sql-developer/

  • 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

  • ALV  download to EXCEL  with column headings etc.

    Getting data from a grid to EXCEL can be done in "List" mode vis system==>save etc but it's not particularly user friendly and in any case if you are displaying a nice ALV why should the user have to switch into LIST mode anyway.
    Anyway here's a decent way to do it and it gives great formatted column headings etc etc.
    1) in the ON_TOOLBAR method add this code
    method ON_TOOLBAR.
    type-pools icon.
    CLEAR ls_toolbar.
    MOVE  0 TO ls_toolbar-butn_type.
        MOVE 'EXCEL' TO ls_toolbar-function.
        MOVE  space TO ls_toolbar-disabled.
        MOVE  icon_xxl TO ls_toolbar-icon.
        MOVE 'Excel' TO ls_toolbar-quickinfo.
        MOVE  'EXCEL' TO ls_toolbar-text.
        APPEND ls_toolbar TO e_object->mt_toolbar.
    2) In the ON_USER_COMMAND method add the following
    (if you have a class defined with SE24 you don't need the commented code).
    method ON_USER_COMMAND.
           FOR EVENT before_user_command OF cl_gui_alv_grid
           IMPORTING
             e_ucomm
             sender.
    CASE e_ucomm.
         .......   other toolbar funcs if you have any
          WHEN 'EXCEL'.
            CALL METHOD me->download_to_excel.
        ENDCASE.
    endmethod.
    3) code this method to download to EXCEL
    method DOWNLOAD_TO_EXCEL.
    FIELD-SYMBOLS:
           <fs0> TYPE STANDARD TABLE,
           <fs1> TYPE STANDARD TABLE.
        ASSIGN g_outtab1->* TO <fs0>.
        ASSIGN g_fldcat1->* TO <fs1>.
           CALL FUNCTION  'LVC_TRANSFER_TO_KKBLO'
          EXPORTING
            it_fieldcat_lvc   = <fs1>
        is_layout_lvc     = m_cl_variant->ms_layout
             is_tech_complete  = ' '
          IMPORTING
            es_layout_kkblo   = ls_layout
            et_fieldcat_kkblo = lt_fieldcat.
        LOOP AT lt_fieldcat INTO lt_fieldcat_wa.
          CLEAR lt_fieldcat_wa-tech_complete.
          IF lt_fieldcat_wa-tabname IS INITIAL.
            lt_fieldcat_wa-tabname = '1'.
            MODIFY lt_fieldcat FROM lt_fieldcat_wa.
          ENDIF.
          l_tabname = lt_fieldcat_wa-tabname.
        ENDLOOP.
        CALL FUNCTION 'ALV_XXL_CALL'
             EXPORTING
                  i_tabname           = l_tabname
                  is_layout           = ls_layout
                  it_fieldcat         = lt_fieldcat
                  i_title             = sy-title
             TABLES
                  it_outtab           = <fs0>
             EXCEPTIONS
                  fatal_error         = 1
                  no_display_possible = 2
                  OTHERS              = 3.
        IF  sy-subrc <> 0.
          MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
                 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        ENDIF.
    endmethod.
    You get nice column headings etc and decently formatted EXCEL spreadsheet.
    For Office 2007 I think you need to apply a SAP note but it certainly works with OFFICE 2003 which is what we are still using.
    Cheers
    jimbo

    Getting data from a grid to EXCEL can be done in "List" mode vis system==>save etc but it's not particularly user friendly and in any case if you are displaying a nice ALV why should the user have to switch into LIST mode anyway.
    Anyway here's a decent way to do it and it gives great formatted column headings etc etc.
    1) in the ON_TOOLBAR method add this code
    method ON_TOOLBAR.
    type-pools icon.
    CLEAR ls_toolbar.
    MOVE  0 TO ls_toolbar-butn_type.
        MOVE 'EXCEL' TO ls_toolbar-function.
        MOVE  space TO ls_toolbar-disabled.
        MOVE  icon_xxl TO ls_toolbar-icon.
        MOVE 'Excel' TO ls_toolbar-quickinfo.
        MOVE  'EXCEL' TO ls_toolbar-text.
        APPEND ls_toolbar TO e_object->mt_toolbar.
    2) In the ON_USER_COMMAND method add the following
    (if you have a class defined with SE24 you don't need the commented code).
    method ON_USER_COMMAND.
           FOR EVENT before_user_command OF cl_gui_alv_grid
           IMPORTING
             e_ucomm
             sender.
    CASE e_ucomm.
         .......   other toolbar funcs if you have any
          WHEN 'EXCEL'.
            CALL METHOD me->download_to_excel.
        ENDCASE.
    endmethod.
    3) code this method to download to EXCEL
    method DOWNLOAD_TO_EXCEL.
    FIELD-SYMBOLS:
           <fs0> TYPE STANDARD TABLE,
           <fs1> TYPE STANDARD TABLE.
        ASSIGN g_outtab1->* TO <fs0>.
        ASSIGN g_fldcat1->* TO <fs1>.
           CALL FUNCTION  'LVC_TRANSFER_TO_KKBLO'
          EXPORTING
            it_fieldcat_lvc   = <fs1>
        is_layout_lvc     = m_cl_variant->ms_layout
             is_tech_complete  = ' '
          IMPORTING
            es_layout_kkblo   = ls_layout
            et_fieldcat_kkblo = lt_fieldcat.
        LOOP AT lt_fieldcat INTO lt_fieldcat_wa.
          CLEAR lt_fieldcat_wa-tech_complete.
          IF lt_fieldcat_wa-tabname IS INITIAL.
            lt_fieldcat_wa-tabname = '1'.
            MODIFY lt_fieldcat FROM lt_fieldcat_wa.
          ENDIF.
          l_tabname = lt_fieldcat_wa-tabname.
        ENDLOOP.
        CALL FUNCTION 'ALV_XXL_CALL'
             EXPORTING
                  i_tabname           = l_tabname
                  is_layout           = ls_layout
                  it_fieldcat         = lt_fieldcat
                  i_title             = sy-title
             TABLES
                  it_outtab           = <fs0>
             EXCEPTIONS
                  fatal_error         = 1
                  no_display_possible = 2
                  OTHERS              = 3.
        IF  sy-subrc <> 0.
          MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
                 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        ENDIF.
    endmethod.
    You get nice column headings etc and decently formatted EXCEL spreadsheet.
    For Office 2007 I think you need to apply a SAP note but it certainly works with OFFICE 2003 which is what we are still using.
    Cheers
    jimbo

  • ALV download to excel problem

    Dear Gurus a problem in alv report downloading to excel:
    on executing the report works fine but when downloading to excel there last digit of bpvno is getting truncated.
    ex: actual bpvno:'4000010' but excel o/p shows as '400001'
    I have declared a field in final internal table as:
    data: bpvno as bseg-belnr,
    (in field catalog)
      fieldcatalog-fieldname   = 'BPVNO'.
      fieldcatalog-seltext_m   = 'BPV No.'.
      fieldcatalog-seltext_L   = 'BPV No.'.
      fieldcatalog-col_pos     = I1.
      fieldcatalog-emphasize   = 'X'.
      append fieldcatalog .
      clear  fieldcatalog.
      I1 = I1 + 1.
    but after specifying the  REF_TABLENAME & REF_FIELDNAME the downloaded excel o/p is correct.
    My questions is:
    1) i want to know what all are mandatory fields to be specified in fieldcatalog & is it compulsory to specify REF_TABLENAME & REF_FIELDNAME .
    if not complusory why the downloaded excel value is being truncated ???
    plz dont send materilas on alv and answer specific to the question....

    Hi,
    I wrote a small program, and for me it worked. My assumption about the seltext was wrong. And I also didn't use output lenght.
    Here is the code.
    REPORT  ZALVTOEXCEL                                                 .
    type-pools slis.
    data : gt_fcat type slis_t_fieldcat_alv.
    data fieldcatalog like line of gt_fcat.
    types : begin of t_belnr,
            bpvno like bseg-belnr.
    types end of   t_belnr.
    data gt_belnr type table of t_belnr.
    data gwa_belnr type t_belnr.
    gwa_belnr-bpvno = '4000010'.
    append gwa_belnr to gt_belnr.
    fieldcatalog-fieldname = 'BPVNO'.
    fieldcatalog-seltext_m = 'BPV No.'.
    fieldcatalog-seltext_L = 'BPV No.'.
    fieldcatalog-col_pos = 1.
    fieldcatalog-emphasize = 'X'.
    append fieldcatalog to gt_fcat.
    clear fieldcatalog.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
       IT_FIELDCAT                        =  gt_fcat
        I_SAVE                            = 'A'
      TABLES
        t_outtab                          =  gt_belnr
    EXCEPTIONS
       PROGRAM_ERROR                     = 1
       OTHERS                            = 2
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    regards,
    Advait.

  • ALV Download to excel truncating fields

    Hi,
    When I use the ALV download button to download to excel, it is truncating the last character of customer number.
    ie customer 20011790 is showing as 2001179.
    Any ideas how to fix this.
    Thanks.

    Looks like Note 855314 has a workaround ... my be more.
    Of course (yuk!), write you own download.
    Best!
    Jim

  • ALV / Download to Excel - columns transposed

    A developer on my team has this problem:
    We have a ALV report that gives the user the option to download to excel.
    The report has columns.
    A,B,C,D (for example)
    but when the user exports to excel ("List > Export > Spreadsheet > Table")
    they get
    A, <b>C, B</b>, D
    Dose anyone know why this happens? We have checked various sites and found OSS note 358644.
    Are we on the right track? Or is there an easy answer to this.
    Thanks in advance.

    Hi Kyle,
      I too faced the same problem lon back. But what we
      found is for currency, date and amount fields it is
      moving to last.
      You also checl the standard program BCALV_GRID_01.
      If you download you can see the same thing happens
      here also.
      Check in your case whether B is date, amout or numeric field.
    Thanks & Regards,
    Siri.
    Kindly award points if the answer is useful.

  • ALV download to EXCEL -- probs with SAPGUI 6.40 and EXCEL 2007

    I have a method in an ALV grid which performs a dowload to excel
    Here's the method
    method download_to_excel.
    field-symbols:
           <fs0> type standard table,
           <fs1> type standard table.
        assign g_outtab1->* to <fs0>.
        assign g_fldcat1->* to <fs1>.
           call function  'LVC_TRANSFER_TO_KKBLO'
          exporting
            it_fieldcat_lvc   = <fs1>
        is_layout_lvc     = m_cl_variant->ms_layout
             is_tech_complete  = ' '
          importing
            es_layout_kkblo   = ls_layout
            et_fieldcat_kkblo = lt_fieldcat.
        loop at lt_fieldcat into lt_fieldcat_wa.
          clear lt_fieldcat_wa-tech_complete.
          if lt_fieldcat_wa-tabname is initial.
            lt_fieldcat_wa-tabname = '1'.
            modify lt_fieldcat from lt_fieldcat_wa.
          endif.
          l_tabname = lt_fieldcat_wa-tabname.
        endloop.
        call function 'ALV_XXL_CALL'
             exporting
                  i_tabname           = l_tabname
                  is_layout           = ls_layout
                  it_fieldcat         = lt_fieldcat
                  i_title             = sy-title
             tables
                  it_outtab           = <fs0>
             exceptions
                  fatal_error         = 1
                  no_display_possible = 2
                  others              = 3.
        if  sy-subrc <> 0.
          message id sy-msgid type 'S' number sy-msgno
                 with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        endif.
    endmethod.
    Basically the method converts the GRID table I'm displaying into the format requred for FMOD ALV_XXL_CALL' -- the field catalog is slightly different but no big deal here.
    This works fine when downloading to  EXCEL 2003 but short dumps when trying to do the same thing for EXCEL 2007.
    Workstation is running Windows XP / SP2 build 2600 in both cases.
    Any fixes etc or should I stick with EXCEL 2003 until forced to upgrade.
    Cheers
    jimbo

    Hi all
    Seems the problem disappeared after applying the latest patch to SAP_GUI 6.40.
    I haven't tried SAP_GUI 7.0 yet.
    Thanks anyway
    Cheers
    jimbo

  • ALV Download to Excel Column Colors Problem

    Hi Experts,
    I've encountered a problem in downloading records from ALV display to excel file.
    The file is downloaded SUCESSFULLY however. When I opened the downloaded file, some columns were filled up with color(yellow) and other fields are not.
    Do anyone have an idea why?

    I have 21 Columns columns. The first 16 columns are filled with yellow colors...

  • ALV Download to Excel

    Hi Experts,
    Currently in my custom program I have an issue regarding downloading ALV to excel file where one of the fields in the report will output more than 400 characters which is in Chinese characters and this field already type to string. The problem is when i download it to excel only the 301 characters is only downloaded to the file.
    Addtnl information:
    The data in the output internal table is complete before going through the FM REUSE_ALV_GRID but when i tried to debug when downloading before it reaches to the GUI_DOWNLOAD it already has incomplete data so this means that this is not a problem for GUI_DOWNLOAD.
    Question:
    Is the problem a SAP ALV download limitation?
    Is there an available solution for this?
    Edited by: Ekitzv on Apr 8, 2011 6:21 AM

    First try to scroll down till the last page, then select all the column manually by putting curser and copy.
    This will solve your issue. i usually do in ths way
    Shayam

  • Excel from abap using OLE, trying to make an excel cell-property currency

    Hello everyone,
    I have build an abap application which generates a price list as a MS Excel file using OLE techniques (ole2incl).
    One small thing in the excel file is lacking and I hope some one can help me out:
    I want to give certain cells in excel the "cell property - currency", so that excel shows the amounts as currency values. 
    Has anyone done or seen that before?
    Thanks a lot in advance.
    Kind regard, Archie Oomen

    Hi,
    I am having a similiar problem trying to fix the CELL format as TEXT.
    No matter how I try, it often ends up as 'GENERAL.
    Have you resolved your issue?
    Prehaps, you could share it if you had already rectify your problem.
    Thanks a lot

Maybe you are looking for