將文字檔案匯入到Excel資料表中

2022-08-26 10:51:17 字數 1212 閱讀 1535

dim r%

sub importfromtextfile()

dim fso as object, sfile as object, blnexist as boolean

dim filename as string, i as integer, icol as integer, linetext as string

const forreading = 1

set fso = createobject("scripting.filesystemobject") '建立filesystemobject物件

filename = "h:\nama_exi_p.tsv" '指定文字檔案名

blnexist = fso.fileexists(filename) '判斷檔案是否存在,如果不存在,則退出過程

if not blnexist then msgbox "檔案不存在!": exit sub

set sfile = fso.opentextfile(filename, forreading) '建立並開啟名為sfile的textstream物件

do while not sfile.atendofstream '如果不是文字檔案的尾端,則讀取資料

linetext = sfile.readline

call getnum1(linetext)

loop

sfile.close

set fso = nothing

set sfile = nothing

end sub

sub getnum1(str as string)

r = r + 1

set reg = createobject("vbscript.regexp")

with reg

.global = true

.ignorecase = true

.pattern = "(\s+)\s+(\s+)\s+(\s+)"

end with

set mc = reg.execute(str)

for each m in mc

cells(r, 1) = m.submatches.item(0)

cells(r, 2) = m.submatches.item(1)

cells(r, 3) = m.submatches.item(2)

next

end sub

通過sqlldr將文字檔案匯入到表中

新來了乙個任務,要求將大量的資料匯入到資料庫的表中。先說明一下,存放資料的資料來源的格式有各種各樣,資料庫是oracle。決定用sqlldr命令來實現。首先要建立乙個ctl檔案,如下 load data 該檔案的解釋 infile test.txt 說明資料來源的 如果是想把原來表中的資料刪除,再新...

將Excel資料匯入到SQL Server資料庫中

1 接受資料匯入的表已經存在。insert into t1 select from openrowset microsoft.jet.oledb.4.0 excel 5.0 hdr yes database c test.xls sheet1 2 匯入資料並生成表。select into t1 fr...

將Excel資料匯入到SQL Server資料庫中

這個方法是到目前為止我見到最好的方法,還有幾個要注意的問題也在下面提到了哦!其中還涉及到要注意到地方都在下面累出來了 1 接受資料匯入的表已經存在。insert into t1 select from openrowset microsoft.jet.oledb.4.0 excel 5.0 hdr ...