sap中abap 导出excel的方法很多,ole是其中一种,但其导出速度比较慢,一般只应用于对excel格式有特别要求的场所.....
TYPE-POOLS: ole2,
slis.
DEFINE add_field.
wa_field-fieldname = &1.
wa_field-reptext_ddic = &2.
wa_field-no_zero = 'X'. "去掉0
* WA_FIELD_EIDT = 'X'.
append wa_field to it_field.
END-OF-DEFINITION.
* 定义变量和字段组
DATA: g_repid TYPE sy-repid,
gs_layout TYPE slis_layout_alv,
wa_field TYPE slis_fieldcat_alv,
it_field TYPE slis_t_fieldcat_alv.
*******************************************************************************
* OLE EXCEL变量
DATA: excel TYPE ole2_object,
workbook TYPE ole2_object,
sheet TYPE ole2_object,
cell TYPE ole2_object.
* CELL1 TYPE OLE2_OBJECT,
* COLUMN TYPE OLE2_OBJECT,
* RANGE TYPE OLE2_OBJECT,
* BORDERS TYPE OLE2_OBJECT,
* button TYPE OLE2_OBJECT,
* int TYPE OLE2_OBJECT,
* FONT TYPE OLE2_OBJECT.
* ROW TYPE OLE2_OBJECT.
* 填充单元格
FORM fill_cell USING i j val.
* CALL METHOD OF EXCEL 'COLUMNS' = COLUMN.
* CALL METHOD OF COLUMN 'AUTOFIT'. "导出EXCEL自动适应宽度
CALL METHOD OF excel 'CELLS' = cell NO FLUSH EXPORTING #1 = i #2 = j.
SET PROPERTY OF cell 'VALUE' = val no flush.
FREE OBJECT cell NO FLUSH.
* GET PROPERTY OF CELL 'FONT' = FONT.
* SET PROPERTY OF FONT 'BOLD' = BOLD .
ENDFORM. "FILL_CELL
* 处理进度条
FORM p_process USING i_processed LIKE sy-tabix
i_total LIKE sy-tabix.
DATA:i_percent TYPE i,
i_text2(72) TYPE c,
i_times TYPE i,
i_proc(10) TYPE c.
i_times = 0.
i_percent = ( i_processed * 100 ) DIV i_total.
i_times = ( i_percent - STRLEN( i_proc ) ) DIV 10.
DO i_times TIMES.
CONCATENATE i_proc '■' INTO i_proc.
CONDENSE i_proc.
ENDDO.
IF i_percent > 0.
WRITE i_percent TO i_text2.
CONDENSE i_text2.
CONCATENATE i_text2 '%' i_proc INTO i_text2.
ENDIF.
CONCATENATE '正在导出EXCEL,目前的进度为' i_text2 INTO i_text2 SEPARATED BY space. "合并文本
CONDENSE i_text2. "缩进文本
* 启动指示钟
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
* PERCENTAGE = I_PERCENT
text = i_text2
EXCEPTIONS
OTHERS = 1
.
ENDFORM. "P_PROCESS
阅读(3143) | 评论(0) | 转发(0) |