VB.NET使用OLDB连接将数据写入Excel
我有一个程序可以在excel文件中输出报告.我在添加行时使用OLEDB连接.
I have a program that output a report in excel file. I use OLEDB Connection in adding rows.
Try
Dim MyConnection As System.Data.OleDb.OleDbConnection
Dim myCommand As New System.Data.OleDb.OleDbCommand
Dim sql As String
MyConnection = New System.Data.OleDb.OleDbConnection _
("provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + _
"'c:\test.xls';Extended Properties=Excel 8.0;")
MyConnection.Open()
myCommand.Connection = MyConnection
sql = "Insert into [Sheet1$] (id,name) values('5','e')"
myCommand.CommandText = sql
myCommand.ExecuteNonQuery()
MyConnection.Close()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
MsgBox("Row Added ")
在 http://www.java-samples.com/showtutorial.php?tutorialid=1051 [ ^ ]
我的问题是在该Excel文件中添加行之前,我必须具有标题作为字段名称.
''这是EXCEL文件中的内容
Found this in http://www.java-samples.com/showtutorial.php?tutorialid=1051[^]
My problem is before I add row in that excel file I must have a header as field names.
''THIS IS THE CONTENT IN EXCEL FILE
id | name
如何在没有该标题的excel文件中添加行.
谢谢...
How can I add row in excel file without that header.
Thanks...
(id,name)values('5','e')" myCommand.CommandText = sql myCommand.ExecuteNonQuery() MyConnection.Close() 捕获,例如 As 异常 MsgBox(例如ToString) 结束 尝试 MsgBox(" )
(id,name) values('5','e')" myCommand.CommandText = sql myCommand.ExecuteNonQuery() MyConnection.Close() Catch ex As Exception MsgBox(ex.ToString) End Try MsgBox("Row Added ")
在 http://www.java-samples.com/showtutorial.php?tutorialid=1051 [ ^ ]
我的问题是在该Excel文件中添加行之前,我必须具有标题作为字段名称.
''这是EXCEL文件中的内容
Found this in http://www.java-samples.com/showtutorial.php?tutorialid=1051[^]
My problem is before I add row in that excel file I must have a header as field names.
''THIS IS THE CONTENT IN EXCEL FILE
id | name
如何在没有该标题的excel文件中添加行.
谢谢...
How can I add row in excel file without that header.
Thanks...
问题出在您的连接字符串上.转到 ConnectionStrings.com [ ^ ],您会发现很多,包括带有标题行的支撑页上的示例.
THe problem is with your connection string. Go to ConnectionStrings.com[^] and you''ll find a ton of them, including samples on supporting sheets with header rows.
这可能会有所帮助: ^ ]
This could be helpful: inserting data in excel[^]