本文主要是介绍EXCEL数据导入到内表中的处理,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
CALL FUNCTION 'ZALSM_EXCEL_TO_INTERNAL_TABLE'EXPORTINGfilename = p_uploadi_begin_col = 2i_begin_row = 7i_end_col = 50i_end_row = 3000sheet_name = '财务视图'TABLESintern = lt_tab[].LOOP AT lt_tab.CONDENSE lt_tab-value.ASSIGN COMPONENT lt_tab-col OF STRUCTURE gs_upload_fi TO <fs>. "动态方法将值传到相应的内表IF <fs> IS ASSIGNED.MOVE lt_tab-value TO <fs>.UNASSIGN <fs>.ENDIF.AT END OF row.APPEND gs_upload_fi TO gt_upload_fi.CLEAR gs_upload_fi.ENDAT.ENDLOOP.
有几个提醒的地方:
一、首先我们要建一个与EXCEL列一模一样的结构,比如上面的gs_upload_fi.
二、上面我把标准的函数拷贝了一个自定义的出来,为的是能够读取多个SHEET页,这里面
* open file in Excelif APPLICATION-HEADER = SPACE or APPLICATION-HANDLE = -1.create object APPLICATION 'Excel.Application'.M_MESSAGE.endif.call method of APPLICATION 'Workbooks' = WORKBOOK.M_MESSAGE.call method of WORKBOOK 'Open'exporting#1 = FILENAME.M_MESSAGE.*->BEGIN OF ADD-ON BY EY_SGQ
** set property of application 'Visible' = 1.
** m_message.if SHEET_NAME = SPACE."用默认模式get property of APPLICATION 'ACTIVESHEET' = WORKSHEET.M_MESSAGE.else.
*-->可以实现读取多个sheetcall method of APPLICATION 'WORKSHEETS' = WORKSHEETexporting#1 = SHEET_NAME.call method of WORKSHEET 'Activate'.M_MESSAGE.endif.
*---END OF------------------------------------------------* mark whole spread sheetcall method of WORKSHEET 'Cells' = H_CELLexporting#1 = I_BEGIN_ROW#2 = I_BEGIN_COL.M_MESSAGE.call method of WORKSHEET 'Cells' = H_CELL1exporting#1 = I_END_ROW#2 = I_END_COL.M_MESSAGE.
注意在主程序里添加代码如上,BEGIN OF ADD ON 中间就是需要添加的代码
三、字段符号一定要UNASIGN,因为在AT END OF语句的影响下,会发生有的字符变成*****而无法写入的情况。
这篇关于EXCEL数据导入到内表中的处理的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!