-1

我有一个csv文件。有很多列,例如“商品”“基础交货中心”“价格单位”等,我不想要,我想删除。如何才能做到这一点

此外,我想1,2,3根据到期时间将这些数字添加到第一列。例子:

SYMBOL     EXPIRY
BARLEYJPR  8/17/2012
BARLEYJPR  9/20/2012
BARLEYJPR  10/19/2012
BARLEYJPR  11/20/2012

在第一行中,我想添加 1,BARLEYJPR因为到期时间august 17th 2012(8/17/2012)是最接近的,然后想添加 2 到BARLEYJPR到期时间,September然后想添加 3 到BARLEYJPR到期时间October,最后 4 到BARLEYJPR到期时间November.

有人能帮我吗?我正在寻找VB6中的代码,因为我已经在VB6中编写了代码以从网站下载文件。

Private Sub Command1_Click()
On Error GoTo Err
Const q As String = "-"
Dim tmp As String, fName As String, Pos As Long, fPath As String
Dim first As Date, last As Date, spath As String, d As Date
cap = Me.Caption
If Dir(App.Path & "\NCDEX\") = "" Then
    MkDir App.Path & "\NCDEX\"
End If
spath = App.Path & "\NCDEX\" ' folder to save files : note trailing \
first = MonthView1
last = MonthView2
'http://www.ncdex.com/Downloads/Bhavcopy_Summary_File/Export_csv/07-04-2012.csv
strURL = "http://www.ncdex.com/Downloads/Bhavcopy_Summary_File/Export_csv/"
    For d = first To last
    ssourceurl = strURL & Format(d, "MM") & q & Format(d, "dd") & q & Format(d, "yyyy") & ".csv"
    fName = Format(d, "dd-mm-yyyy") & ".csv"
    slocalfile = spath & fName
    Me.Caption = "Downloading  " & fName
    Call DeleteUrlCacheEntry(ssourceurl)
    URLDownloadToFile 0&, ssourceurl, slocalfile, BINDF_GETNEWESTVERSION, 0&
    Debug.Print ssourceurl
Next
Me.Caption = cap
'YOU CAN TAKE THIS BELOW OUT IF U DONT WANT IT
MsgBox "Saved to " & spath, vbInformation + vbOKOnly, "Success!"
Exit Sub
Err:     MsgBox "Error", vbCritical + vbOKOnly, "Market Was Closed"
End Sub
4

1 回答 1

0

您可以使用 Jet 引擎将 CSV 文件读取到记录集并像使用 ADO 处理数据库一样对其进行操作。

一些示例和参考站点:

于 2012-07-27T11:47:52.887 回答