Export DataGridView to Excel (xls) format
-
Hi! I need to export data contained in the DataGridView control to Excel. The code provided here does the work, but not fully - when Excel opens the file, it recognises it like a "Tab delimited values" and import wizard appears. This is too complicated for (my) end users, so I need a way to write "real" xls file, without the need of end user action. Do you know how can I do this? The code is: '(tab is DataGridView control containing data) Dim fileText As System.Text.StringBuilder = New System.Text.StringBuilder() 'exporting column names For Each col As DataGridViewColumn In tab.Columns If col.Visible = True Then fileText.Append(col.Name) fileText.Append(vbTab) End If Next fileText.Append(vbCrLf) 'export cell values For Each row As DataGridViewRow In tab.Rows For Each theCell As DataGridViewCell In row.Cells If theCell.Visible = True Then fileText.Append(theCell.Value.ToString()) fileText.Append(vbTab) End If Next fileText.Append(vbCrLf) 'moving to the next row Next My.Computer.FileSystem.WriteAllText("Test.xls", fileText.ToString(), False) Any help would be appreciated! Thank you in advance! Veljko
-
Hi! I need to export data contained in the DataGridView control to Excel. The code provided here does the work, but not fully - when Excel opens the file, it recognises it like a "Tab delimited values" and import wizard appears. This is too complicated for (my) end users, so I need a way to write "real" xls file, without the need of end user action. Do you know how can I do this? The code is: '(tab is DataGridView control containing data) Dim fileText As System.Text.StringBuilder = New System.Text.StringBuilder() 'exporting column names For Each col As DataGridViewColumn In tab.Columns If col.Visible = True Then fileText.Append(col.Name) fileText.Append(vbTab) End If Next fileText.Append(vbCrLf) 'export cell values For Each row As DataGridViewRow In tab.Rows For Each theCell As DataGridViewCell In row.Cells If theCell.Visible = True Then fileText.Append(theCell.Value.ToString()) fileText.Append(vbTab) End If Next fileText.Append(vbCrLf) 'moving to the next row Next My.Computer.FileSystem.WriteAllText("Test.xls", fileText.ToString(), False) Any help would be appreciated! Thank you in advance! Veljko
is this a windows application Bulbul Bhuwania
-
Hi! I need to export data contained in the DataGridView control to Excel. The code provided here does the work, but not fully - when Excel opens the file, it recognises it like a "Tab delimited values" and import wizard appears. This is too complicated for (my) end users, so I need a way to write "real" xls file, without the need of end user action. Do you know how can I do this? The code is: '(tab is DataGridView control containing data) Dim fileText As System.Text.StringBuilder = New System.Text.StringBuilder() 'exporting column names For Each col As DataGridViewColumn In tab.Columns If col.Visible = True Then fileText.Append(col.Name) fileText.Append(vbTab) End If Next fileText.Append(vbCrLf) 'export cell values For Each row As DataGridViewRow In tab.Rows For Each theCell As DataGridViewCell In row.Cells If theCell.Visible = True Then fileText.Append(theCell.Value.ToString()) fileText.Append(vbTab) End If Next fileText.Append(vbCrLf) 'moving to the next row Next My.Computer.FileSystem.WriteAllText("Test.xls", fileText.ToString(), False) Any help would be appreciated! Thank you in advance! Veljko
I am having the same problem. Please provide me the solution if you happen to get one. With Best Regards, Mayur
-
is this a windows application Bulbul Bhuwania
-
I am having the same problem. Please provide me the solution if you happen to get one. With Best Regards, Mayur
-
albCode, thank you for the reply, but I have allready found many sources for converting in ASP using web pages.. What I need has to be done using Windows application.