ITPub博客

首页 > Linux操作系统 > Linux操作系统 > OLE上传EXCEL

OLE上传EXCEL

原创 Linux操作系统 作者:ytfsrs2008 时间:2010-03-30 13:13:18 0 删除 编辑

include ole2incl.

 

tables: mara,marc,makt.

 data: myexcel type ole2_object,

       myworkbook type ole2_object,

       mycell type ole2_object.

      

 data: begin of itab occurs 0,

        werks like marc-werks,

        matnr like mara-matnr,

        maktx like makt-maktx,

       end of itab.

 data: i type i, j type i.

 

 parameters: p_file like rlgrap-filename default 'C:\aaa.xls'.

 at selection-screen on value-request for p_file.

   perform. get_file_form. using p_file.

 

 start-of-selection.  (*注意不要使用END-OF-SELECTION语句)

   create object myexcel 'excel.application'.

   call method  of myexcel 'workbooks' = myworkbook.

   call method of myworkbook 'open' exporting #1 = p_file.

    set property of myexcel 'visible' = 0.

   i = 2.

   do 30 times.  (不要使用DO.. Enddo语句,容易造成死循环)

     perform. fill_itab_form. using i 1 itab-werks.

     perform. fill_itab_form. using i 2 itab-matnr.

     perform. fill_itab_form. using i 3 itab-maktx.

     append itab.

     clear itab.

     i = i + 1.

   enddo.

 

   call method of myexcel 'QUIT'.

   free object myworkbook.

   free object myexcel.

 

   sort itab by werks.

   loop at itab.

      write:/ itab-werks,itab-matnr,itab-maktx.

   endloop.

*&---------------------------------------------------------------------*

*&      Form  get_file_form

*&---------------------------------------------------------------------*

FORM. get_file_form  USING    FILE.

 CALL FUNCTION 'WS_FILENAME_GET'

       EXPORTING

            def_path         = 'C:\'

            mask             = ',*.xls.'

            mode             = 'O'

            title            = 'Choose Input file'(001)

       IMPORTING

            filename         = file

       EXCEPTIONS

            inv_winsys       = 1

            no_batch         = 2

            selection_cancel = 3

            selection_error  = 4

            OTHERS           = 5.

ENDFORM.

*&---------------------------------------------------------------------*

*&      Form  fill_itab_form

*&---------------------------------------------------------------------*

FORM. fill_itab_form  USING  p_i  p_j  p_value.

  call method of myexcel 'cells' = mycell

       exporting #1 = p_i #2 = p_j.

  get property of mycell 'value' = p_value.

  free object mycell.

ENDFORM.

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/15117617/viewspace-630800/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: 常用的MRP函数
请登录后发表评论 登录
全部评论

注册时间:2008-10-31

  • 博文量
    52
  • 访问量
    63015