Creating .Excel File from a DatagridVIew

In order to fetch all the data from the grid view and create a .xls file of the data, use the following code .

private void CreateXLS()
{
DataTable dt = (DataTable)dgSearch .DataSource;
dt.WriteXml(@"C:\ABC.xls",System.Data.XmlWriteMode.IgnoreSchema);
dt.Dispose();
}


In case you get an error while converting the dgsearch.datasource to Datatable, convert the dgsearch.datasource to dataview and by using the property of dataview ie "Totable" convert it to datatable

Comments

Popular posts from this blog

SPFx: Develop using SharePoint Framework without Installing all the dependecies.

SharePoint Online: Elevated Permissions....with love

Powershell: Filling up an Existing Excel Sheet with data from SQL Server