內錶匯出兩份excel 乙份是抬頭,乙份是明細。
data: l_filetable type filetable,
ls_filetable type file_table,
ls_rc type i.
data lv_str_i type char20.
data: l_path type string.
data: l_path_item type string.
data: l_path_tmp type string.
data : lt_row type lvc_t_roid, "內錶
ls_row type lvc_s_roid. "工作區
data:begin of t_fieldnames occurs 0
, name type char20,
end of t_fieldnames.
clear: l_filetable,ls_rc,l_path.
data:lv_char type string,
lv_head type string value 'bom抬頭'
, lv_item type string value 'bom明細'
. data:len type int4,
len1 type int4.
lv_char = sy-datum. "&& sy-uzeit.
lv_head = lv_head &&
'-'&& lv_char.
lv_item = lv_item &&
'-'&& lv_char &&
'.xls'
.*檔案路徑選擇
call method cl_gui_frontend_services=
>file_open_dialog
exporting
window_title =
'請選擇本地檔案' "對話方塊的標題
default_extension =
'xls' "預設的檔案字尾名
default_filename = lv_head
file_filter =
'xls檔案(*.xls)|全部檔案 (*.*)|*.*|' "檔案開啟的filter
changing
file_table = l_filetable
rc = ls_rc
exceptions
file_open_dialog_failed =
1 cntl_error =
2 error_no_gui =
3 not_supported_by_gui =
4 others =
5.*讀取路徑
loop at l_filetable into ls_filetable.
l_path = ls_filetable-filename.
endloop.
clear t_fieldnames.
clear t_fieldnames-name.
t_fieldnames-name =
'零件表編號'
. clear t_fieldnames-name.
t_fieldnames-name =
'客戶編碼'
. clear t_fieldnames-name.
t_fieldnames-name =
'客戶**'
. clear t_fieldnames-name.
t_fieldnames-name =
'成品編號'
. clear t_fieldnames-name.
t_fieldnames-name =
'成品描述'
. clear t_fieldnames-name.
t_fieldnames-name =
'箱種箱型'
. clear t_fieldnames-name.
t_fieldnames-name =
'版本'
. clear t_fieldnames-name.
t_fieldnames-name =
'建立日期'
. clear t_fieldnames-name.
t_fieldnames-name =
'備註'
. clear t_fieldnames-name.
t_fieldnames-name =
'預留欄位一'
. clear t_fieldnames-name.
t_fieldnames-name =
'預留欄位二'
. clear t_fieldnames-name.
t_fieldnames-name =
'預留欄位三'
. call function 'gui_download'
exporting
filename = l_path
filetype =
'dat'
codepage =
'8404'
tables
data_tab = gt_exhead
fieldnames = t_fieldnames.
if sy-subrc ne 0.
message 'bom抬頭匯出失敗!' type 'e'
. endif.
clear:t_fieldnames[
],t_fieldnames-name.
clear t_fieldnames-name.
t_fieldnames-name =
'零件表編號'
. clear t_fieldnames-name.
t_fieldnames-name =
'行專案'
. clear t_fieldnames-name.
t_fieldnames-name =
'元件名稱'
. clear t_fieldnames-name.
t_fieldnames-name =
'厚度'
. clear t_fieldnames-name.
t_fieldnames-name =
'展開寬'
. clear t_fieldnames-name.
t_fieldnames-name =
'展開長'
. clear t_fieldnames-name.
t_fieldnames-name =
'規格'
. clear t_fieldnames-name.
t_fieldnames-name =
'材質'
. clear t_fieldnames-name.
t_fieldnames-name =
'數量'
. clear t_fieldnames-name.
t_fieldnames-name =
'單位'
. clear t_fieldnames-name.
t_fieldnames-name =
'重量'
. clear t_fieldnames-name.
t_fieldnames-name =
'預留欄位一'
. clear t_fieldnames-name.
t_fieldnames-name =
'bom元件'
. clear t_fieldnames-name.
t_fieldnames-name =
'製造屬性'
. clear t_fieldnames-name.
t_fieldnames-name =
'圖號'
. clear t_fieldnames-name.
t_fieldnames-name =
'分類'
. clear t_fieldnames-name.
t_fieldnames-name =
'預留欄位二'
. clear t_fieldnames-name.
t_fieldnames-name =
'預留欄位三'
. len =
strlen
( l_path )
. len1 = len -
18. l_path_tmp =
l_path
(len1)
. l_path_item = l_path_tmp && lv_item.
call function 'gui_download'
exporting
filename = l_path_item
filetype =
'dat'
codepage =
'8404'
tables
data_tab = gt_exitem
fieldnames = t_fieldnames.
if sy-subrc ne 0.
message 'bom明細匯出失敗!' type 'e'
. endif.
C 將DateTable表資料匯出到Excel中
在visual c 中呼叫excel 並不像讀取excel 中的資料那麼容易了,因為在visual c 中呼叫excel 要使用到excel的com元件。以vs2005為例,首先新增引用 在com選項中,新增microsfot excel 11.0 objet library。然後在程式中引入命名空...
DataTable匯出到word或excel
using system using system.data using system.configuration using system.collections using system.web using system.web.security using system.web.ui usin...
C 建立Excel檔案並將資料匯出到Excel檔案
工具原料 windows 7,visual studio 2010,microsoft office 2007 建立解決方案 選單 新建 專案 windows窗體應用程式 新增兩個datagridview,乙個textbox,兩個按鈕 如下圖 新增excel資源 c 建立excel檔案,這裡實際上是...