将 Excel 导入到具有相同布局的内部 table
Importing Excel to internal table with same layout
我知道功能模块ALSM_EXCEL_TO_INTERNAL_TABLE。此 FM 创建一个包含三列(行、列、值)的内部 table。但我想创建一个内部 table,其布局与我的 Excel sheet 相同。我怎样才能做到这一点?
如果您使用 FM ALSM_EXCEL_TO_INTERNAL_TABLE 上传数据,您可以循环遍历此 FM 使用的内部 table(您提到的具有行、列、值的那个)并填充您自己的相应地,内部 table(看起来像 Excel sheet)。
如果您在前台上传 excel,则可以使用 class cl_mass_spreadsheet_service。请参阅下面的示例代码:
DATA:
lv_file TYPE if_mass_spreadsheet_types=>file_name,
lt_result TYPE STANDARD TABLE OF zsd_salesorder_create. "your result table
lv_file = 'C:\some_file.xlsx'.
cl_mass_spreadsheet_service=>fill_table(
EXPORTING
iv_file = lv_file "full path+name of file. See method navigate_to_file below
iv_from_file = abap_true "use to upload from excel/CSV
iv_from_clipboard = abap_false "use to copy directly from clipbiard
iv_tabname = 'Order_Create' "can be whatever
CHANGING
ct_table = lt_result "if ct_table have the same column names as the excel file, the order of the columns does not matter
).
你可以使用
cl_mass_spreadsheet_service=>import_from_file
同样,但没有 ddic 结构。
不幸的是,这些方法实际上会打开并显示 EXCEL...
我知道功能模块ALSM_EXCEL_TO_INTERNAL_TABLE。此 FM 创建一个包含三列(行、列、值)的内部 table。但我想创建一个内部 table,其布局与我的 Excel sheet 相同。我怎样才能做到这一点?
如果您使用 FM ALSM_EXCEL_TO_INTERNAL_TABLE 上传数据,您可以循环遍历此 FM 使用的内部 table(您提到的具有行、列、值的那个)并填充您自己的相应地,内部 table(看起来像 Excel sheet)。
如果您在前台上传 excel,则可以使用 class cl_mass_spreadsheet_service。请参阅下面的示例代码:
DATA:
lv_file TYPE if_mass_spreadsheet_types=>file_name,
lt_result TYPE STANDARD TABLE OF zsd_salesorder_create. "your result table
lv_file = 'C:\some_file.xlsx'.
cl_mass_spreadsheet_service=>fill_table(
EXPORTING
iv_file = lv_file "full path+name of file. See method navigate_to_file below
iv_from_file = abap_true "use to upload from excel/CSV
iv_from_clipboard = abap_false "use to copy directly from clipbiard
iv_tabname = 'Order_Create' "can be whatever
CHANGING
ct_table = lt_result "if ct_table have the same column names as the excel file, the order of the columns does not matter
).
你可以使用 cl_mass_spreadsheet_service=>import_from_file 同样,但没有 ddic 结构。
不幸的是,这些方法实际上会打开并显示 EXCEL...