以下代码是打开 excel 文件并从中读取,我想处理 excel 文件以便能够删除它:
Dim strNewPath As String = Server.MapPath("~/UploadedExcel/" & strFileName & strFileType)
'Connection String to Excel Workbook
If strFileType.Trim = ".xls" Then
connString2 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strNewPath & ";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=2"""
ElseIf strFileType.Trim = ".xlsx" Then
connString2 = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & strNewPath & ";Extended Properties=""Excel 12.0;HDR=Yes;IMEX=2"""
End If
query = "SELECT * FROM [Sheet1$]"
'Create the connection object
conn2 = New OleDbConnection(connString2)
'Open connection
If conn2.State = ConnectionState.Closed Then conn2.Open()
'Create the command object
cmd = New OleDbCommand(query, conn2)
da = New OleDbDataAdapter(cmd)
ds = New DataSet()
da.Fill(ds, "Staff")
' up.insertExcel(ds)
da.Dispose()