Skip to Content
DATA: LS_BUTTON LIKE LINE OF GT_BUTTON.
CALL METHOD SUPER->DO_PREPARE_OUTPUT
  EXPORTING
    IV_FIRST_TIME = IV_FIRST_TIME
    .
*** ls_button-type     = 'DOWNLOAD'."cl_thtmlb_util=>gc_done.
*** IF me->view_group_context->is_view_in_display_mode( me ) = abap_false.
***   ls_button-enabled = abap_true .
***   ELSE.     ls_button-enabled = abap_true .
***   ENDIF.
****  ls_button-on_click = 'DOWNLOAD'.client_
***   ls_button-on_click = 'download_file( );'.
***   ls_button-tooltip = 'Sonuç tablosunu excel''e aktarır.'.
***   ls_button-text = 'Excel''e aktar '.
***   ls_button-icon_src = cl_bsp_mimes=>sap_icon( id = 'ICON_TREND_DOWN' ).
***   APPEND ls_button TO GT_BUTTON.
***   CLEAR ls_button.

Or with simple javascript button;

<thtmlb:fileUpload id="fileUpDown" />

<thtmlb:button id = "DOWNLOAD"

iconSrc       = "ICON_XLS"

tooltip       = "Excel'e aktarır. Önce hedef dosya seçiniz."

text          = "Excel'e aktar"

onClientClick = "download_file()" />

Then define a function that accomplish the job, iterateting the code will give you basic understanding of how things work;

But jus before that you’ll need a picker to select target .xls which is like;

<thtmlb:fileUpload id="fileUpDown" />

<thtmlb:button id = "DOWNLOAD"

iconSrc       = "ICON_XLS"

tooltip       = "Excel'e aktarır. Önce hedef dosya seçiniz."

text          = "Excel'e aktar"

onClientClick = "download_file()" />

function download_file(){



var  ActiveRows="0",

fileNameD="";

fileNameD=document.getElementById("<%= controller->component_id %>_fileUpDown").value;

if ( fileNameD == "" ) {

alert("Download." + "\n" + " " + "\n" + "Please choose a target Excel file.");

return;

}

if ( fileNameD != "" ) {

  alert("Download." + "\n" + " " + "\n" + "The download is to" + "\n" + " " + "\n" + fileNameD);

  Excel = new ActiveXObject("Excel.Application");

  Book = Excel.Workbooks.Open( fileNameD );

  ActiveRows = Book.Worksheets("Sheet1").Range("A1.IV64000").CurrentRegion.Rows.Count;

   <%

  types: begin of typ_zproduct_bp,

        val1 type char5,

        val2 type char5,

        end of typ_zproduct_bp.

        FIELD-SYMBOLS <fany> type any."need any to assign all field types

        data lv_string type string.

        data lv_row type i value 0.

        data lv_col TYPE i VALUE 0.

        data:

        ls_zproduct_bp type typ_zproduct_bp,

        lt_zproduct_bp type table of typ_zproduct_bp.

        ls_zproduct_bp-val1 = 'alp'.

        ls_zproduct_bp-val2 = 'keser'.

        APPEND ls_zproduct_bp to lt_zproduct_bp.

  loop at lt_zproduct_bp into ls_zproduct_bp.   "row

    lv_row = sy-tabix + 1.

    lv_col = 0.   "col

    while lv_col lt 3.

      add 1 to lv_col.   " read cell data:

         ASSIGN COMPONENT lv_col OF STRUCTURE ls_zproduct_bp to <fany>.

      lv_string = <fany>.

      lv_string = lv_string.

      " put cell data:

      %> Book.Worksheets("Sheet1").Cells(<%= lv_row %>, <%= lv_col %>).value = "<%= lv_string %>";

       <%   endwhile.   endloop. %>

       Excel.Workbooks.Close;

return nameDownload(fileNameD);



  }

Those elements in your .htm file should be enough for the job.

Take care

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

Leave a Reply