OLE

DATA: excel    TYPE ole2_object,
      workbook TYPE ole2_object,
      sheet    TYPE ole2_object,
      cell     TYPE ole2_object.

FORM frm_open_excel USING p_fullpath.
  CREATE OBJECT excel 'EXCEL.APPLICATION'.
  SET PROPERTY OF excel 'Visible' = 0.
  CALL METHOD OF excel 'Workbooks' = workbook.
  CALL METHOD OF workbook 'Open'
    EXPORTING
      #1 = p_fullpath.
  CALL METHOD OF excel 'Sheets' = sheet
    EXPORTING
      #1 = 1.
  CALL METHOD OF sheet 'Activate'.
ENDFORM.

FORM frm_close_excel .
  GET PROPERTY OF excel 'ActiveWorkbook' = workbook.
  CALL METHOD OF workbook 'SAVE'.
  CALL METHOD OF excel 'QUIT'.
  FREE OBJECT sheet.
  FREE OBJECT workbook.
  FREE OBJECT excel.
ENDFORM.

FORM frm_fill_cell  USING    p_row
                             p_col
                             p_value.
  CALL METHOD OF excel 'CELLS' = cell
    EXPORTING
      #1  = p_row
      #2  = p_col.
  SET PROPERTY OF cell 'VALUE' = p_value.
ENDFORM.

FORM frm_clipboard_to_excel USING p_sheet
                                  p_row
                                  p_col.
  DATA: l_range TYPE ole2_object,
        l_cell  TYPE ole2_object.

  CALL METHOD OF p_sheet 'Cells' = l_cell
    EXPORTING #1 = p_row #2 = p_col.

  CALL METHOD OF p_sheet 'Range' = l_range
    EXPORTING #1 = l_cell #2 = l_cell.

  CALL METHOD OF l_range 'SELECT'.
  CALL METHOD OF p_sheet 'PASTE'.

  FREE OBJECT: l_range, l_cell.
ENDFORM.

FORM delete_columns USING colnum.
  CALL METHOD OF application 'COLUMNS' = columns
    EXPORTING #1 = colnum.
  CALL METHOD OF columns 'DELETE'.
ENDFORM.

FORM  delete_row USING i_row.
  CALL METHOD OF application 'ROWS' = rows
    EXPORTING #1 = i_row.
  CALL METHOD OF rows 'DELETE'.
ENDFORM.

CALL METHOD cl_gui_frontend_services=>file_save_dialog
CALL FUNCTION 'DOWNLOAD_WEB_OBJECT'
CLASS cl_abap_char_utilities DEFINITION LOAD.
  l_separator = cl_abap_char_utilities=>horizontal_tab.
CALL METHOD cl_gui_frontend_services=>clipboard_export

 

posted on 2016-08-22 10:24  小伙儿  阅读(452)  评论(0编辑  收藏  举报