Non so se fa quello che vi serve, cmq ecco come utilizzo io i files excel (visti come un db)
codice:Public Function CreateExcelOrder(ByVal userID As Integer, ByVal DataRows As Data.DataTable, ByVal BaseFilePath As String, _ ByVal FilePath As String, Optional ByVal Notes As String = "", Optional ByVal FileName As String = "", Optional ByVal Reference As String = "") As String Dim con As OleDb.OleDbConnection Dim cmd As OleDb.OleDbCommand Dim SaveFilePath As String = FilePath If FileName = "" Then SaveFilePath = SaveFilePath & "\" & CStr(userID) & ".xls" Else SaveFilePath = SaveFilePath & "\" & FileName End If SaveFilePath = Replace(SaveFilePath, "\\", "\") System.IO.File.Copy(BaseFilePath, SaveFilePath) con = New OleDb.OleDbConnection con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & SaveFilePath & ";" & _ "Extended Properties = ""Excel 8.0;HDR=YES;""" con.Open() cmd = New OleDb.OleDbCommand cmd.Connection = con cmd.CommandText = "Insert Into [Foglio1$] (Codice_Fidi, Quantità, Appunti, Riferimenti, Tipologia_acquisizione) Values ('" & DataRows.Rows(0).Item(0) & _ "', " & DataRows.Rows(0).Item(1) & ", '" & Notes & "', '" & Reference & "', '03')" cmd.ExecuteNonQuery() For i As Integer = 1 To DataRows.Rows.Count - 1 cmd.CommandText = "Insert Into [Foglio1$] (Codice_Fidi, Quantità) Values ('" & DataRows.Rows(i).Item(0) & _ "', " & DataRows.Rows(i).Item(1) & ")" cmd.ExecuteNonQuery() Next cmd.Dispose() cmd = Nothing con.Dispose() con = Nothing Return FileName End Function

Rispondi quotando