We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How Can I Export data from Datagrid to Excel

Thread ID:





120568 Sep 25,2015 06:00 PM UTC Sep 28,2015 09:46 AM UTC WinForms 1
Tags: GridDataBoundGrid(Classic)
Richard lubanga
Asked On September 25, 2015 06:00 PM UTC

I need urgent help. I want to export data from datagrid to Excel but not with datatable. I would like to know if it is possible with datagrid view.
I would appreciate help
here is the code to export  

        private void buttonAdv1_Click(object sender, EventArgs e)
            //Exports the DataTable to a spreadsheet.

            #region Workbook Initialize
            //New instance of XlsIO is created.[Equivalent to launching MS Excel with no workbooks open].
            //The instantiation process consists of two steps.

            //Step 1 : Instantiate the spreadsheet creation engine.
            ExcelEngine excelEngine = new ExcelEngine();

            //Step 2 : Instantiate the excel application object.
            IApplication application = excelEngine.Excel;
            //Set the Workbook version as Excel 97to2003
            if (this.rdbExcel97.Checked)
                application.DefaultVersion = ExcelVersion.Excel97to2003;
                fileName = "ExportToExcel.xls";
            //Set the Workbook version as Excel 2007
            else if (this.rdbExcel2007.Checked)
                application.DefaultVersion = ExcelVersion.Excel2007;
                fileName = "ExportToExcel.xlsx";
            //Set the Workbook version as Excel 2010
            else if (this.rdbExcel2010.Checked)
                application.DefaultVersion = ExcelVersion.Excel2010;
                fileName = "ExportToExcel.xlsx";
            //Set the Workbook version as Excel 2010
            else if (this.rdbExcel2013.Checked)
                application.DefaultVersion = ExcelVersion.Excel2013;
                fileName = "ExportToExcel.xlsx";
            //A new workbook is created.[Equivalent to creating a new workbook in MS Excel]
            //The new workbook will have 3 worksheets
            IWorkbook workbook = application.Workbooks.Create(1);

            //The first worksheet object in the worksheets collection is accessed.
            IWorksheet worksheet = workbook.Worksheets[0];

            #region Export DataTable to Excel
            //Export DataTable.
            if (this.gridDataBoundGrid1.DataSource != null)
                worksheet.ImportDataTable((GridDataBoundGrid)this.gridDataBoundGrid1.DataSource, true, 3, 1, -1, -1);
                MessageBox.Show("There is no datatable to export, Please import a datatable first", "Error");

                //Close the workbook.

            #region View the Workbook
            //Message box confirmation to view the created spreadsheet.
            if (MessageBox.Show("Do you want to view the workbook?", "Workbook has been created",
                MessageBoxButtons.YesNo, MessageBoxIcon.Information)
                == DialogResult.Yes)
                //Launching the Excel file using the default Application.[MS Excel Or Free ExcelViewer]
                // Exit

Adhikesevan Kothandaraman [Syncfusion]
Replied On September 28, 2015 09:46 AM UTC

Hi Richard,

Thanks for contacting Syncfusion Support.

Exporting Grid to an Excel can be achieved using the Converter.GridToExcel method. Please refer to the following Knowledge Base for more details,




This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon