Export DataGridView To Excel In c# Windows Application Step By Step

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello viewers welcome to programming gig i am here with a new tutorial that is export directly view to excel in c sharepoint spam application [Music] start microsoft visual studio 2015 okay now i'm gonna create a new project file new project select windows and select on this form application select location just click on browse yes select your location my location is c [Music] project yes [Music] folder is c sharp con okay and the name of this application is export data gdp to excel click on okay okay the application is created now resize this form go to the toolbox under label control now i just uh designed this form to load that in datagridview and then export data from datagridview to excel okay text of this level is export to excel tutorial form okay for college button page and the font size is 18 okay now change the back color of this form back color is yes now this is looking nice and little title label also displaying perfectly this button control i'll use to load data in dedicated view so button back color is purple and for color is button page font size is 12 and text is default access button one so just change the text text is load data [Music] okay research this button yes now this is looking nice add a dataget view from the toolbox yes this is the degree view now go to the button click event in this button click on i'll write code to load data in datagridview this is server explorer now add a connection first of all go to the sql server to check the database table and records server name version pc login essay and password is sql server authentication password yes these are the database and my database name is uh programming db table is product underscore setup underscore tab let's check the records yes these are the records in the database table productivity item name design and column okay now right click and add connection in the data connection server explorer server name is your option pc yeah authentication ask authentication username sa and password is exclusive authentication password and then select the database my database name is programming dbs click on ok yes it's added in the data connection and now show table data yes the record is displaying in there a table okay now first of all all right sql connection to connect with the sql server so sql connection to use sql connection you should add namespace using system.data.sql client so move the cursor and click on the light that yes sql client is data that sql client is added now food connection listing to get the connection string uh just right click on the database in the server explorer and click on property see that this is the connection string just double click to copy the connection string and paste it in the double quotation okay israelis yes okay but password is like star so you should put your sql certification password let's call command mysql command is to select records from the sql server database table to get a grid view so scale command command equal to musical command select star prom student sorry select star from product underscore set of underscore tab okay you can see that table name in the left side in server explorer okay initialize the connection con c sql data adapter d equal to new sql data adapter command then data table database equal to new data table finally fill the date in dt data table d dot fill dt then data grid view one that is under data to sequel to dt okay let's debug [Music] start debugging okay click the button to load data from sql server database to data grid view yes you can see the records displaying in the windows form for factory from the specified database and now i'm gonna insert one more records to display the data grid view okay data yes the record is also displaying in the windows form perfectly now add one more button control to export data export the data gate view to excel change the text of this button button text is export to excel okay now data object copy data equal to datagridview1.get clipboard content if coffee data [Music] not equal to null i mean if that if you have any records then it will execute okay clipboard dot set data object copy data okay you should add reference microsoft excel 15.0 object library so go to the solution explorer right click on the references click on add reference in the com in the com just select microsoft excel 15.0 object library okay this is microsoft excel you can see select microsoft excel 15.0 object library click on ok yes now you can use excel okay put microsoft dot office dot inner dot excel dot application equal to [Music] function excel f equal to new microsoft dot opis dot in a troop dot excel dot application okay now excel f dot visible equal to true okay now excel workbook so excel dot workbook excel w boogie okay w microsoft dot office dot net proof dot excel [Music] worksheet declare worksheet excel sheet okay now object missed data equal to system dot reflection dot missing dot value okay excel w book equal to xlf dot workbook dot add means data okay now excel sheet equal to microsoft.office.net.excel dot worksheet [Music] this is xlw book dot worksheets dot get item one okay [Music] microsoft database dot integer dot excel dot range numerically range xlr dot office dot netrope dot excel [Music] dot range [Music] excel sheet okay that cells one row index and column index xlr dot select finally excel sheet dot test special and then xlr then object link displays the icon icon file name that all are just footage missing type dot missing type dot missing and the type dot missing and then typed it missing finally not html format true okay now debug [Music] yes it's debugging load data and export to excel click on export to excel yes it's exporting but it's a export only the first cell below because it's selected only the first cell value so so i have to select all the all the records in the dedicated view so that you do under select all okay now debug load data export yes it's selecting and now exported all the records from the dataget view successfully thanks for watching this tutorial if you like this tutorial please subscribe my channel and press the bell icon for upcoming [Music] videos [Music] do [Music] you
Info
Channel: ProgrammingGeek
Views: 31,132
Rating: undefined out of 5
Keywords: programminggeek, export datagridview to excel in c#, export gridview to excel c#, c# export to excel, export datagridview to excel windows application, how to export datagridview data instantly to excel on button click, export grid data to excel in c#, visual studio c# export to excel, export dataview to excel c, c# tutorial for beginners
Id: 7-6j_IzIY-s
Channel Id: undefined
Length: 12min 17sec (737 seconds)
Published: Sun Nov 29 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.