*&---------------------------------------------------------------------*
*& 向excel中的指定行插入N行
*&---------------------------------------------------------------------*
FORM excel_row_insert USING lcobj_sheet
lc_row
lc_count.
DATA lc_range TYPE ole2_object.
DATA h_borders TYPE ole2_object.
DO lc_count TIMES.
CALL METHOD OF lcobj_sheet 'Rows' = lc_range
EXPORTING #1 = 2.
CALL METHOD OF lc_range 'Copy'. "COPY第2行插入一个新行
CALL METHOD OF lcobj_sheet 'Rows' = lc_range
EXPORTING #1 = lc_row.
CALL METHOD OF lc_range 'Insert'.
CALL METHOD OF lc_range 'ClearContents'. "是否需要清空Cell
ENDDO.
ENDFORM. "excel_row_insert
*&---------------------------------------------------------------------*
*& Form fill_range
*&---------------------------------------------------------------------*
* text 填充EXCEL 单元格
*----------------------------------------------------------------------*
* -->VALUE(F_ROW) text
* -->VALUE(F_COL) text
* -->VALUE(F_VALUE) text
*----------------------------------------------------------------------*
FORM fill_range USING VALUE(excel)
value(f_row)
value(f_col)
value(f_value).
DATA:
row TYPE i,
col TYPE i.
DATA: CELL TYPE OLE2_OBJECT.
row = f_row.
col = f_col.
* 先设置单元格文本格式
IF f_col = 4.
* SET PROPERTY OF LV_CELL 'ColumnWidth' = 8.
SET PROPERTY OF CELL 'NumberFormat' = '@'.
ENDIF.
CALL METHOD OF excel 'CELLS' = cell
EXPORTING
#1 = row
#2 = col.
SET PROPERTY OF cell 'VALUE' = f_value.
ENDFORM. "fill_range
*&---------------------------------------------------------------------*
*& Form borderrange
*&---------------------------------------------------------------------*
* text:设置EXCEL中所插入的数据行边框线格式
*----------------------------------------------------------------------*
* -->LCOBJ_EXCEL text
* -->RANGE text
*----------------------------------------------------------------------*
FORM borderrange USING lcobj_excel
range .
DATA: lc_cell TYPE ole2_object ,
lc_borders TYPE ole2_object .
CALL METHOD OF lcobj_excel 'RANGE' = lc_cell
EXPORTING
#1 = range.
DO 4 TIMES .
CALL METHOD OF lc_cell 'BORDERS' = lc_borders
EXPORTING #1 = sy-index.
SET PROPERTY OF lc_borders 'LineStyle' = '1'.
SET PROPERTY OF lc_borders 'WEIGHT' = 2. "4=max
SET PROPERTY OF lc_borders 'ColorIndex' = '1'.
ENDDO.
FREE OBJECT lc_borders.
FREE OBJECT lc_cell.
ENDFORM. "borderrange
或者用DOI导出模板,模板列设为文本格式