ABAP EXCEL模板匯入

2021-10-01 18:15:05 字數 4758 閱讀 8682

用rlgrap-filename定義檔案選擇框的型別

parameters: fidata like rlgrap-filename default 'c:\fidata.xls' obligatory.
用 cl_gui_frontend_services類中的file_open_dialog 開啟檔案對話方塊

form file_f4 using file.

data:

lt_filetable type filetable,

lf_rc type i.

call method cl_gui_frontend_services=>file_open_dialog

exporting

multiselection = abap_false

changing

file_table = lt_filetable

rc = lf_rc

exceptions

file_open_dialog_failed = 1

cntl_error = 2

error_no_gui = 3

not_supported_by_gui = 4

others = 5.

if sy-subrc <> 0.

message id sy-msgid type 's' number sy-msgno

display like 'e'

with sy-ms**1 sy-ms**2 sy-ms**3 sy-ms**4.

exit.

endif.

* number of selected filed must be equal to one.

check lf_rc = 1.

* access selected file

data:

ls_file type file_table.

read table lt_filetable into ls_file index 1.

check sy-subrc = 0.

file = ls_file-filename.

endform.

用 cl_gui_frontend_services類中的file_exist 判斷檔案是否存在

form file_check.

data: file type string.

data: result.

clear result.

file = fidata.

call method cl_gui_frontend_services=>file_exist

exporting

file = file

receiving

result = result

exceptions

cntl_error = 1

error_no_gui = 2

wrong_parameter = 3

not_supported_by_gui = 4

others = 5.

if sy-subrc <> 0.

message id sy-msgid type sy-msgty number sy-msgno

with sy-ms**1 sy-ms**2 sy-ms**3 sy-ms**4.

endif.

if result eq space.

message 'file not exist ' type 'e' display like 's'.

endif.

endform.

用函式alsm_excel_to_internal_table上傳excel檔案內容,l_tab存放表的內容

call function 'alsm_excel_to_internal_table'

exporting

filename = fidata

i_begin_col = 1

i_begin_row = 1

i_end_col = 26

i_end_row = n_col

tables

intern = l_tab.

定義l_tab為alsmex_tabline型別的內錶

data:l_tab  like  alsmex_tabline occurs 0 with header  line.
用row和col控制字段上傳至內錶,完整**如下

form frm_upload .

data: i type i.

data j type i.

data l_count type i value 1.

data:l_tab like alsmex_tabline occurs 0 with header line.

i = 2.

call function 'alsm_excel_to_internal_table'

exporting

filename = fidata

i_begin_col = 1

i_begin_row = 1

i_end_col = 26

i_end_row = n_col

tables

intern = l_tab.

sort l_tab by row.

loop at l_tab.

at new row.

l_count = l_count + 1.

endat.

endloop.

while i <= 1000.

j = i - 1.

loop at l_tab where row = j .

case l_tab-col.

when 1.

t_upload-field = l_tab-value.

when 2.

t_upload-field1 = l_tab-value.

when 3.

t_upload-field2 = l_tab-value.

when 4.

t_upload-field3 = l_tab-value.

when 5.

t_upload-field4 = l_tab-value.

when 6.

t_upload-field5 = l_tab-value.

when 7.

t_upload-field6 = l_tab-value.

when 8.

t_upload-field7 = l_tab-value.

when 9.

t_upload-field8 = l_tab-value.

when 10.

t_upload-field9 = l_tab-value.

when 11.

t_upload-field10 = l_tab-value.

when 12.

t_upload-field11 = l_tab-value.

when 13.

t_upload-field12 = l_tab-value.

when 14.

t_upload-field13 = l_tab-value.

when 15.

t_upload-field14 = l_tab-value.

when 16.

t_upload-field15 = l_tab-value.

when 17.

t_upload-field16 = l_tab-value.

when 18.

t_upload-field17 = l_tab-value.

when 19.

t_upload-field18 = l_tab-value.

when 20.

t_upload-field19 = l_tab-value.

when 21.

t_upload-field20 = l_tab-value.

when 22.

t_upload-field21 = l_tab-value.

when 23.

t_upload-field22 = l_tab-value.

when 24.

t_upload-field23 = l_tab-value.

when 25.

t_upload-field24 = l_tab-value.

when 26.

t_upload-field25 = l_tab-value.

endcase.

endloop.

clear t_upload.

i = i + 1.

endwhile.

i_upload = t_upload.

if l_tab is initial.

message i001(zdev).

exit.

endif.

endform.

ArcGIS Engine 匯入mxd模板

匯入模板有兩種思路 1.直接將當前pagelayout替換為模板的pagelayout,再同步一下map。2.獲取模板pagelayout的所有要素,更新到當前pagelayout。直接替換模板 public void importtemplate axmapcontrol mapcontrol,a...

如何匯入Excel模板

第乙個引數是檔案的名字,第二個引數是檔案的路徑,是否需要刪除 當我點選瀏覽,上傳填寫完資料的excel文件,此時匯入資料的按鈕也可以進行提交,如果需要哪些資料,就選擇核取方塊進行勾選即可 當選擇乙個檔案的時候 當點選匯入按鈕的時候 protected void importexcel click o...

POI匯入匯出Excel模板

hssfworkbook 是操作excel2003以前 包括2003 的版本,副檔名是.xls xssfworkbook 是操作excel2007的版本,副檔名是.xlsx 以xssfworkbook為例 匯出 public void getexcelbyboiler catch filenotfo...