Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,706 members, 7,809,686 topics. Date: Friday, 26 April 2024 at 01:08 PM

Datagridview Export To Excel Vb.net - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Datagridview Export To Excel Vb.net (4372 Views)

How To Print All Records From A Datagridview In Vb.net / I Need A Help To Write A Simple Login Form Using Vb.net / Post Ur Vb 6.0 Questions Here (2) (3) (4)

(1) (Reply)

Datagridview Export To Excel Vb.net by bigafees: 11:42am On Jan 06, 2012
Please, i need code to export datagridview to excel in VB.Net 2008

Please include the Liberary that i will imports
Re: Datagridview Export To Excel Vb.net by Kobojunkie: 3:25pm On Jan 06, 2012
i went on google and copy pasted the string "export datagridview to excel in VB.Net 2008". the very first result link was http://xldennis./2008/02/12/export-data-from-datagridview-to-excel/
Re: Datagridview Export To Excel Vb.net by stephen9530: 4:50am On Mar 22, 2012
Hi,

You can use the following VB.NET code (via Spire.DataExport, a Free Data Export Component):


Private Sub btnText_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnText.Click
Dim oleDbConnection1 As New System.Data.OleDb.OleDbConnection()
oleDbConnection1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\..\..\..\Database\demo.mdb"

Dim oleDbCommand1 As New System.Data.OleDb.OleDbCommand()
oleDbCommand1.CommandText = "select * from parts"
oleDbCommand1.Connection = oleDbConnection1

Dim txtExport1 As New Spire.DataExport.TXT.TXTExport()

txtExport1.ActionAfterExport = Spire.DataExport.Common.ActionType.OpenView
txtExport1.DataFormats.CultureName = "zh-CN"
txtExport1.DataFormats.Currency = "c"
txtExport1.DataFormats.DateTime = "yyyy-M-d H:mm"
txtExport1.DataFormats.Float = "g"
txtExport1.DataFormats.[Integer] = "g"
txtExport1.DataFormats.Time = "H:mm"
txtExport1.DataEncoding = Spire.DataExport.Common.EncodingType.ASCII
txtExport1.SQLCommand = oleDbCommand1

oleDbConnection1.Open()

txtExport1.ExportType = Spire.DataExport.TXT.TextExportType.SYLK
txtExport1.FileName = "sample.slk"
txtExport1.SaveToFile()

txtExport1.ExportType = Spire.DataExport.TXT.TextExportType.CSV
txtExport1.FileName = "sample.csv"
txtExport1.SaveToFile()

txtExport1.ExportType = Spire.DataExport.TXT.TextExportType.DIF
txtExport1.FileName = "sample.dif"
txtExport1.SaveToFile()

txtExport1.ExportType = Spire.DataExport.TXT.TextExportType.TXT
txtExport1.FileName = "sample.txt"
txtExport1.SaveToFile()
End Sub

(1) (Reply)

To Be a Whiz In Cybersecurity, Where Do I Start? / My Rant... / Is Data Science Worth Learning

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 8
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.