<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Sample code to download data to .CSV file using OLE method in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/sample-code-to-download-data-to-csv-file-using-ole-method/m-p/5092585#M1182054</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need some sample code to download data to .CSV file using OLE method.&lt;/P&gt;&lt;P&gt;Also i need to format one of the columns to text. I have not used OLE method before, Please&lt;/P&gt;&lt;P&gt;provide me with some sample code for this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;Srilakshmi.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 06 Feb 2009 09:04:13 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2009-02-06T09:04:13Z</dc:date>
    <item>
      <title>Sample code to download data to .CSV file using OLE method</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sample-code-to-download-data-to-csv-file-using-ole-method/m-p/5092585#M1182054</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need some sample code to download data to .CSV file using OLE method.&lt;/P&gt;&lt;P&gt;Also i need to format one of the columns to text. I have not used OLE method before, Please&lt;/P&gt;&lt;P&gt;provide me with some sample code for this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;Srilakshmi.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Feb 2009 09:04:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sample-code-to-download-data-to-csv-file-using-ole-method/m-p/5092585#M1182054</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-02-06T09:04:13Z</dc:date>
    </item>
    <item>
      <title>Re: Sample code to download data to .CSV file using OLE method</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sample-code-to-download-data-to-csv-file-using-ole-method/m-p/5092586#M1182055</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;check for the link ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://www.sapdevelopment.co.uk/ms/ms_excel.htm" target="test_blank"&gt;http://www.sapdevelopment.co.uk/ms/ms_excel.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Inside that code try the below thing....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DESCRIBE TABLE it[] LINES wf_it_line.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; CALL METHOD OF wf_excel 'Cells' = wf_cellx&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;EXPORTING&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#1 = 1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#2 = 5.&lt;/P&gt;&lt;P&gt;CALL METHOD OF wf_excel 'Cells' = wf_celly&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;EXPORTING&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#1 = wf_it_line&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#2 = 5.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; CALL METHOD OF wf_excel 'Range' = wf_cellr&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;EXPORTING&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#1 = wf_cellx&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#2 = wf_celly.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; &lt;STRONG&gt;SET PROPERTY OF wf_cellr 'NumberFormat' = '@' .&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The above code will make the 5th coloumn, as text format . where you will get '0004' instead of '4' .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can change the value given to  #2 to format your required coloumn.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Feb 2009 09:11:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sample-code-to-download-data-to-csv-file-using-ole-method/m-p/5092586#M1182055</guid>
      <dc:creator>former_member195383</dc:creator>
      <dc:date>2009-02-06T09:11:24Z</dc:date>
    </item>
    <item>
      <title>Re: Sample code to download data to .CSV file using OLE method</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sample-code-to-download-data-to-csv-file-using-ole-method/m-p/5092587#M1182056</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;can you paste the code from that link, because that link is not opening for me.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Srilakshmi.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Feb 2009 09:25:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sample-code-to-download-data-to-csv-file-using-ole-method/m-p/5092587#M1182056</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-02-06T09:25:10Z</dc:date>
    </item>
    <item>
      <title>Re: Sample code to download data to .CSV file using OLE method</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sample-code-to-download-data-to-csv-file-using-ole-method/m-p/5092588#M1182057</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi I m posting the below part which is part of my code....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data :      wf_cell1 TYPE ole2_object,&lt;/P&gt;&lt;P&gt;        wf_cellx TYPE ole2_object,&lt;/P&gt;&lt;P&gt;        wf_celly TYPE ole2_object,&lt;/P&gt;&lt;P&gt;        wf_cellr TYPE ole2_object,&lt;/P&gt;&lt;P&gt;        wf_it_line type i,&lt;/P&gt;&lt;P&gt;       wf_cell2 TYPE ole2_object,&lt;/P&gt;&lt;P&gt;       wf_excel TYPE ole2_object,&lt;/P&gt;&lt;P&gt;       wf_mapl TYPE ole2_object,&lt;/P&gt;&lt;P&gt;       wf_map TYPE ole2_object,&lt;/P&gt;&lt;P&gt;       wf_worksheet TYPE ole2_object,&lt;/P&gt;&lt;P&gt;       wf_tmp_filename LIKE rlgrap-filename,&lt;/P&gt;&lt;P&gt;       wf_cell TYPE ole2_object,&lt;/P&gt;&lt;P&gt;       wf_range TYPE ole2_object,&lt;/P&gt;&lt;P&gt;       wf_gs_font TYPE ole2_object,&lt;/P&gt;&lt;P&gt;       wf_zl TYPE ole2_object,&lt;/P&gt;&lt;P&gt;       wf_sheet2 TYPE ole2_object,&lt;/P&gt;&lt;P&gt;       wf_sheet3 TYPE ole2_object,&lt;/P&gt;&lt;P&gt;       flg_stop(1) TYPE c,&lt;/P&gt;&lt;P&gt;       wf_deli(1) TYPE c,&lt;/P&gt;&lt;P&gt;       l_rc TYPE i,&lt;/P&gt;&lt;P&gt;       wf_cnt TYPE i.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;CLEAR it.
  REFRESH it.
  CREATE OBJECT application 'excel.application'.
*Start the excel.

  CLEAR : wa_sheets.
  ASSIGN wf_deli TO &amp;lt;fs&amp;gt; TYPE 'X'.
  t_hex-l_tab = co_c09.
  &amp;lt;fs&amp;gt; = t_hex-l_tab.  "Assign the delimiter to field symbol.

* Test heading in the report start.





  LOOP AT tb_output1.
  

    CONCATENATE tb_output1-field1
                tb_output1-field2
 
    INTO it
    SEPARATED BY wf_deli.
    APPEND it.
    CLEAR it.
  ENDLOOP.

 

******

  DATA: excel TYPE ole2_object ,
        workbook TYPE ole2_object,
        range TYPE ole2_object.

  DATA: sheetname(10) VALUE 'TEST ',c_row TYPE i,
  scnt TYPE i,
  val(20), wb(2).


  CREATE OBJECT excel 'EXCEL.APPLICATION'.


  SET PROPERTY OF excel 'VISIBLE' = 0.


*
  IF wf_excel-header = space OR wf_excel-handle = -1.
    CREATE OBJECT wf_excel 'EXCEL.APPLICATION'.
  ENDIF.

*--- get list of workbooks, initially empty
  CALL METHOD OF wf_excel 'Workbooks' = wf_mapl.
  SET PROPERTY OF wf_excel 'Visible' = 1.



  CALL METHOD OF wf_mapl 'Add' = wf_map.




* Sheet 1---Begin .
  gv_sheet_name = text-t36.

  GET PROPERTY OF wf_excel 'Sheets' = wf_sheet3 .
  CALL METHOD OF wf_sheet2 'Add' = wf_map.

  GET PROPERTY OF wf_excel 'ACTIVESHEET' = wf_worksheet.
  SET PROPERTY OF wf_worksheet 'Name' = gv_sheet_name .

*--Formatting the area of additional data 1 and doing the BOLD
  CALL METHOD OF wf_excel 'Cells' = wf_cell1
  EXPORTING
  #1 = 1
  #2 = 1.
  CALL METHOD OF wf_excel 'Cells' = wf_cell2
  EXPORTING
  #1 = 1
  #2 = 50.
  CALL METHOD OF wf_excel 'Range' = wf_cell
  EXPORTING
  #1 = wf_cell1
  #2 = wf_cell2.



  GET PROPERTY OF wf_cell 'Font' = wf_gs_font .
  SET PROPERTY OF wf_gs_font 'Bold' = 1 .



* Changing the format 2nd coloumn
* so that 0 is not removed at the start if present.
  CLEAR wf_it_line.

  DESCRIBE TABLE it[] LINES wf_it_line.
  wf_it_line = wf_it_line + 8.
  CLEAR : wf_cellx, wf_celly, wf_cellr.
  CALL METHOD OF wf_excel 'Cells' = wf_cellx
  EXPORTING
   #1 = 1
   #2 = 2.

  CALL METHOD OF wf_excel 'Cells' = wf_celly
  EXPORTING
   #1 = wf_it_line
   #2 = 2.

  CALL METHOD OF wf_excel 'Range' = wf_cellr
   EXPORTING
 #1 = wf_cellx
 #2 = wf_celly.

  SET PROPERTY OF wf_cellr 'NumberFormat' = '@' .



***************
  CLEAR wf_it_line.


* cell test  end


*  DATA wf_l_rc TYPE i.

  CALL METHOD cl_gui_frontend_services=&amp;gt;clipboard_export
    IMPORTING
      data                 = it[]
    CHANGING
      rc                   = l_rc
    EXCEPTIONS
      cntl_error           = 1
      error_no_gui         = 2
*      not_supported_by_gui = 3
      OTHERS               = 4.

  CALL METHOD OF wf_excel 'Cells' = wf_cell1
    EXPORTING
     #1 = 1
     #2 = 1.
  CALL METHOD OF wf_excel 'Cells' = wf_cell2
    EXPORTING
     #1 = 1
     #2 = 1.
  CALL METHOD OF wf_excel 'Range' = wf_range
    EXPORTING
     #1 = wf_cell1
     #2 = wf_cell2.



  CALL METHOD OF wf_range 'Select'.
  CALL METHOD OF wf_worksheet 'Paste'.



* Sheet 1---End Exp.




* Saving the Excel


  wf_fname = pa_file.

  GET PROPERTY OF excel 'ActiveSheet' = sheet.

  FREE OBJECT wf_worksheet.

  GET PROPERTY OF wf_excel 'ActiveWorkbook' = wf_mapl.
*call method of wf_mapl 'SAVEAS' exporting #1 = 'D:\exceldoc3.xls'
*#2 = 1.
  CALL METHOD OF wf_mapl 'SAVEAS' EXPORTING #1 = wf_fname
  #2 = 1.

  IF sy-subrc = 0.

  ENDIF.


  CALL METHOD OF wf_mapl 'CLOSE'.
  CALL METHOD OF wf_excel 'QUIT'.


  FREE OBJECT wf_worksheet.
  FREE OBJECT wf_excel.




*--- disconnect from Excel
  FREE OBJECT wf_zl.
  FREE OBJECT wf_mapl.
  FREE OBJECT wf_map.
  FREE OBJECT wf_excel.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;in the above code tb_output1 contains the two coloumns whose data u wanna show. &lt;/P&gt;&lt;P&gt;U are transferring that to it[] which will be converted to Excel through the above ole technique.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Feb 2009 09:38:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sample-code-to-download-data-to-csv-file-using-ole-method/m-p/5092588#M1182057</guid>
      <dc:creator>former_member195383</dc:creator>
      <dc:date>2009-02-06T09:38:02Z</dc:date>
    </item>
  </channel>
</rss>

