*声明变量
DATA:LV_INDEX TYPE I.
DATA:N TYPE I.
*常量声明
CONSTANTS:
LC_START_COL TYPE I VALUE '1',
LC_START_ROW TYPE I VALUE '2',
LC_END_COL TYPE I VALUE '256',
LC_END_ROW TYPE I VALUE '65536'.
FIELD-SYMBOLS: <F>.
*内表声明
*change by alan 2007.05.05 type table from KCDE_INTERN
* to ALSMEX_TABLINE
DATA:ITAB TYPE ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE.
CLEAR: ITAB,N.
REFRESH ITAB.
CALL FUNCTION'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
FILENAME = P_FILE
I_BEGIN_COL = LC_START_COL
I_BEGIN_ROW = LC_START_ROW
I_END_COL = LC_END_COL
I_END_ROW = LC_END_ROW
TABLES
INTERN = ITAB
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2.
IF NOT SY-SUBRC IS INITIAL.
MESSAGE E002(FB).
ENDIF.
CHECK NOT ITAB[] IS INITIAL.
SORT ITAB BY ROW COL.
*将EXCEL中数据写入内表中
LOOP AT ITAB.
MOVE:ITAB-COL TO LV_INDEX.
ASSIGN COMPONENT LV_INDEX OF STRUCTURE TAB TO <F>.
MOVE:ITAB-VALUE TO <F>.
AT END OF ROW.
N = N + 1.
TAB-XH = N.
*对于概算项目前面加J,目的保留前导零
CONCATENATE 'J' TAB-AUFEX INTO TAB-AUFEX.
APPEND TAB.
CLEAR TAB.
ENDAT.
ENDLOOP.