标签:abap读取excel表格函数 alsm_excel_to_intern kcd_excel_ole_to_int
KCD_EXCEL_OLE_TO_INT_CONVERT 与 ALSM_EXCEL_TO_INTERNAL_TABLE 都是 ABAP 中常用的读取EXCEL文件的函数。这两者最大的区别在于 KCD_EXCEL_OLE_TO_INT_CONVERT 中对单元格值最大长度限制为 32,ALSM_EXCEL_TO_INTERNAL_TABLE 对单元格值最大长度限制为 50。
1、KCD_EXCEL_OLE_TO_INT_CONVERT用法如下:
**从已知文件名读入内表
* CALL FUNCTION ‘KCD_EXCEL_OLE_TO_INT_CONVERT‘
* EXPORTING
* FILENAME = P_FILE
* I_BEGIN_COL = 1
* I_BEGIN_ROW = 1
* I_END_COL = 20
* I_END_ROW = 65535
* TABLES
* INTERN = I_EXCEL[]
* EXCEPTIONS
* INCONSISTENT_PARAMETERS = 1
* UPLOAD_OLE = 2
* OTHERS = 3.
*
* IF SY-SUBRC <> 0.
* MESSAGE ‘打开文件错误,请检查文件,确保关闭文件!‘ TYPE ‘E‘.
* STOP.
* ENDIF.
*
* REFRESH ITAB.
* CLEAR ITAB.
*
*
* LOOP AT I_EXCEL.
* CASE I_EXCEL-COL.
* WHEN ‘001‘.
* WRITE I_EXCEL-VALUE TO ITAB-MATNR.
* WHEN ‘002‘.
* WRITE I_EXCEL-VALUE TO ITAB-MAKTX.
*
* ENDCASE.
* AT END OF ROW.
* APPEND ITAB.
* CLEAR ITAB.
* ENDAT.
* ENDLOOP.
2、ALSM_EXCEL_TO_INTERNAL_TABLE用法如下:
FIELD-SYMBOLS: <fs>.
REFRESH ITEXCEL.
CLEAR ITEXCEL.
CALL FUNCTION ‘ALSM_EXCEL_TO_INTERNAL_TABLE‘
EXPORTING
FILENAME = P_FILE
I_BEGIN_COL = 1
I_BEGIN_ROW = 1
I_END_COL = 255
I_END_ROW = 65536
TABLES
INTERN = ITEXCEL[].
REFRESH ITAB.
CLEAR ITAB.
LOOP AT ITEXCEL.
ON CHANGE OF ITEXCEL-row.
IF sy-tabix NE 1.
APPEND ITAB.
CLEAR ITAB.
ENDIF.
ENDON.
ASSIGN COMPONENT ITEXCEL-col OF STRUCTURE ITAB TO <fs>. "动态方法将值传到相应的内表
<fs> = ITEXCEL-value.
ENDLOOP.
APPEND ITAB. "这句不要忘记,要把最后一条APPEND到内表中
版权声明:本文为博主原创文章,未经博主允许不得转载。
读Excel表格的两个函数ALSM_EXCEL_TO_INTERNAL_TABLE、KCD_EXCEL_OLE_TO_INT_CONVERT
标签:abap读取excel表格函数 alsm_excel_to_intern kcd_excel_ole_to_int
原文地址:http://blog.csdn.net/champaignwolf/article/details/47008521