Quantcast
Channel: SCN : Unanswered Discussions - ABAP Development
Viewing all articles
Browse latest Browse all 8768

ALV download to Excel onto desktop using OLE concept.

$
0
0


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
  SETPROPERTYOF wa_excel  'VISIBLE' = 1. "In background Mode
  CALLMETHODOF wa_excel 'WORKBOOKS' = w_workbook.
  CALLMETHODOF w_workbook 'ADD'. "Create a new Workbook
  SETPROPERTYOF wa_excel 'SheetsInNewWorkbook' = 3. "No of sheets
* Downloading header details to first sheet
  PERFORM download_sheet TABLES i_final USING1'Master Material Details'.
  GETPROPERTYOF wa_excel 'ActiveSheet' = w_worksheet.
* Protect the first worksheet with a password
  CALLMETHODOF w_worksheet 'PROTECT
    EXPORTING #1 = 'infy@123'.
* Save the Excel file
  GETPROPERTYOF wa_excel 'ActiveWorkbook' = w_workbook.
  CALLMETHODOF w_workbook 'SAVEAS'
    EXPORTING #1 = p_infile.
  FREEOBJECT: w_worksheet, wa_excel.

 

 

 

 

FORM download_sheet TABLES p_tab  USING p_sheet TYPEi   p_name  TYPE string.

  CALLMETHODOF wa_excel 'WORKSHEETS' = w_worksheet
    EXPORTING
    #1 = p_sheet.

  CALLMETHODOF w_worksheet 'ACTIVATE'.
  SETPROPERTYOF w_worksheet 'NAME' = p_name.
  CALLMETHODOF wa_excel 'Range' = w_range
    EXPORTING
    #1 = 'A1'
    #2 = 'D1'.

  CALLMETHODOF w_range 'INTERIOR' = w_int.
  SETPROPERTYOF w_int 'ColorIndex' = 6.
  SETPROPERTYOF w_int 'Pattern' = 1.
* Initially unlock all the columns( by default all the columns are locked )
  CALLMETHODOF wa_excel 'Columns' = w_columns.
  SETPROPERTYOF w_columns 'Locked' = 0.
* Locking and formatting first column
  CALLMETHODOF wa_excel 'Columns' = w_columns
   EXPORTING
   #1 = 1.
* Locking and formatting second column
  CALLMETHODOF wa_excel 'Columns' = w_columns
    EXPORTING
    #2 = 2.
  SETPROPERTYOF w_columns  'Locked' = 2.
  SETPROPERTYOF w_columns  'NumberFormat' = '@'.
* Export the contents in the internal table to the clipboard
  CALLMETHOD 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
  CALLMETHODOF w_worksheet 'Paste'.
* Autofit the columns according to the contents
  CALLMETHODOF wa_excel 'Columns' = w_columns.
  CALLMETHODOF 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.


Viewing all articles
Browse latest Browse all 8768

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>