• 简单的OO ALV显示ALV及下载


    REPORT OO_ALV.
    CLASS OO_ALV DEFINITION.
      PUBLIC SECTION.
        METHODS:GET_DATA IMPORTING AMOUNT TYPE I,"取数
          DISPLAY_ALV,"显示ALV
          DOWNLOAD_ALV."下载ALV
      PRIVATE SECTION.
        DATA:IT_SPFLI TYPE STANDARD TABLE OF SPFLI.
        DATA:LO_SALV TYPE REF TO  CL_SALV_TABLE.
        DATA:O_COLUMNS   TYPE REF TO CL_SALV_COLUMNS_TABLE.
        DATA: LO_CONVERTER TYPE REF TO ZCL_EXCEL_CONVERTER.
    ENDCLASS.
    
    CLASS OO_ALV IMPLEMENTATION.
      METHOD GET_DATA.
        SELECT * FROM SPFLI INTO CORRESPONDING FIELDS OF TABLE IT_SPFLI UP TO AMOUNT ROWS .
      ENDMETHOD.
      METHOD DISPLAY_ALV.
        TRY.
            CL_SALV_TABLE=>FACTORY(
              EXPORTING
                LIST_DISPLAY = ABAP_FALSE
              IMPORTING
                R_SALV_TABLE = LO_SALV
              CHANGING
                T_TABLE      = IT_SPFLI ).
          CATCH CX_SALV_MSG .
        ENDTRY.
        O_COLUMNS = LO_SALV->GET_COLUMNS( ).
        O_COLUMNS->SET_OPTIMIZE( ABAP_TRUE ). "自动优化列宽
        "调用显示alv
        LO_SALV->DISPLAY( ).
      ENDMETHOD.
      METHOD DOWNLOAD_ALV.
        "创建zcl_excel_converter类
        CREATE OBJECT LO_CONVERTER.
        TRY .
            LO_CONVERTER->CONVERT(
              EXPORTING
                IO_ALV        = LO_SALV
                IT_TABLE      = IT_SPFLI
                I_ROW_INT     = 1
                I_COLUMN_INT  = 1
                ).
          CATCH ZCX_EXCEL.
        ENDTRY.
        "调用write_file方法导出excel
        LO_CONVERTER->WRITE_FILE( I_PATH = 'D:/test1.xlsx' ).
      ENDMETHOD.
    ENDCLASS.
    
    START-OF-SELECTION.
      DATA(OUTPUT) = NEW OO_ALV( ).
      OUTPUT->GET_DATA( 10 ).
      OUTPUT->DISPLAY_ALV( ).
      OUTPUT->DOWNLOAD_ALV( ).

  • 相关阅读:
    014 停止进程
    014 创建进程的函数使用
    014 进程 获取当前目录 获取当前文件搜在目录 获取环境变量
    013 Windows进程及线程
    012 CopyFile
    011 异步I/O处理 003
    010 异步I/O处理 002
    MVVM
    ORM
    MVC
  • 原文地址:https://www.cnblogs.com/BruceKing/p/12372848.html
Copyright © 2020-2023  润新知