阿宝
找工作中,求帮助,谢谢!!! QQ:810487238

1.打开对话框,为选择相关的文档。

form get_file_name .
  call method cl_gui_frontend_services=>file_open_dialog
    exporting
      window_title     = 'Select File'
      default_filename = '*.xls'
      multiselection   = ' '
    changing
      file_table       = it_tab
      rc               = gd_subrc.

  loop at it_tab into p_file.
*    so_fpath-sign = 'I'.
*    so_fpath-option = 'EQ'.
*    append so_fpath.
  endloop.

endform.                    " Get_file_name

 

 

2.将Excel档转换成内表TABLE

form get_excel .
*  DATA : LT_INTERN TYPE  KCDE_CELLS OCCURS 0 WITH HEADER LINE.
  data: lt_intern like alsmex_tabline occurs 0 with header line.

  data : ld_index type i.
  field-symbols : <fs>.

  clear   : it_data.
  refresh : it_data.
  clear   : lt_intern.
  refresh : lt_intern.

  call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
    exporting
      filename                = p_file
      i_begin_col             = p_scol
      i_begin_row             = p_srow
      i_end_col               = p_ecol
      i_end_row               = p_erow
    tables
      intern                  = lt_intern
    exceptions
      inconsistent_parameters = 1
      upload_ole              = 2
      others                  = 3.
  if sy-subrc <> 0.
    message id sy-msgid type sy-msgty number sy-msgno
          with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  endif.

 

*  CALL FUNCTION 'KCD_EXCEL_OLE_TO_INT_CONVERT'
*    EXPORTING
*      FILENAME                = P_FILE
*      I_BEGIN_COL             = P_SCOL
*      I_BEGIN_ROW             = P_SROW
*      I_END_COL               = P_ECOL
*      I_END_ROW               = P_EROW
*    TABLES
*      INTERN                  = LT_INTERN
*    EXCEPTIONS
*      INCONSISTENT_PARAMETERS = 1
*      UPLOAD_OLE              = 2
*      OTHERS                  = 3.
*  IF SY-SUBRC <> 0.
*    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*  ENDIF.

  if lt_intern[] is initial.
    format color col_background intensified.
    write:/ 'No Data Uploaded'.
    exit.
  else.
    sort lt_intern by row col.
    loop at lt_intern.
      move lt_intern-col to ld_index.
      assign component ld_index of structure it_data to <fs>.
      move lt_intern-value to <fs>.
      at end of row.
        append it_data.
        clear  it_data.
      endat.
    endloop.
  endif.
endform.                    "GET_EXCEL

 

posted on 2012-04-10 15:45  阿宝兴荣  阅读(547)  评论(0编辑  收藏  举报