I'm using OLE to connect to a database using VB.NET, and show the results in a DataGridView.
I want to export the data that is in the DataGridView to an Excel format file, i.e., the user can save the content of the DataGridView as MS Excel file.
相关问题
- 'System.Threading.ThreadAbortException' in
- Excel sunburst chart: Some labels missing
- how to use special characters like '<'
- Error handling only works once
- Excel formula in VBA code
相关文章
- vb.net 关于xps文件操作问题
- Checking for DBNull throws a StrongTypingException
- Get column data by Column name and sheet name
- Using the typical get set properties in C#… with p
- programmatically excel cells to be auto fit width
- Unregister a XLL in Excel (VBA)
- Load a .NET assembly from the application's re
- C# equivalent of VB DLL function declaration (Inte
I tested it and its work for me.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click DATAGRIDVIEW_TO_EXCEL((DataGridView1)) ' PARAMETER: YOUR DATAGRIDVIEW End Sub
Private Sub DATAGRIDVIEW_TO_EXCEL(ByVal DGV As DataGridView) Try Dim DTB = New DataTable, RWS As Integer, CLS As Integer
End Sub
The simplest way to do this is to use the textfieldparser class in microsoft.visualbasic.fileio (msdn link). The psuedocode would be:
create a textfieldparser object, set the file to open (*.csv), and decoding.
write the column headers
loop through the datagridview or its datsource print to the text file
User can now open the file in excel.
That is my quick answer, I will look to see if there is a better way to do it.
I found that copyfromrecordset is the fastest way.