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 : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Using Grid View for Excel

Thread ID:

Created:

Updated:

Platform:

Replies:

118359 Mar 2,2015 02:58 PM UTC Mar 4,2015 06:38 AM UTC WinForms 1
loading
Tags: GridDataBoundGrid(Classic)
Kevin Shay
Asked On March 2, 2015 02:58 PM UTC

I'm trying to find the correct syntax for searching the columns in a Syncfusion Grid. I'm exporting data to Excel with a button click from data in the grid viewer. I'm basically viewing a bunch of data in the Syncfusion equivalent of a data grid viewer for the standard C# VS. Below is the code. It errors on the Columns and Rows section of the code. Perhaps there is an assembly reference I am not seeing but I've added almost all of them and it still doesn't work.

for (int i =1; i < CK_QA_DataGridView.Columns.Count + 1, i++)
{
     ExcelApp.Cells[1, i] = CK_QA_DataGridView.Columns[i - 1].HeaderText;
}

for (int i = 0; i < CK_QA_DataGridview.Rows.Count; i++)
{
    for (int j = 0; j < CK_QA_DataGridview.Columns.Count; j++)
     { 
              ExcelApp.Cells[i + 2, j +1] = CK_QA_DataGridView.Rows[i].Cells[j].Value.ToString();
     }
}

Any help would be appreciated.

Solai A L [Syncfusion]
Replied On March 4, 2015 06:38 AM UTC

Hi Kevin,

Thank you for your interest in Syncfusion Products.

In order to achieve your requirement please make use of QueryImportExportCellInfo event of GridExcelConvertercontrol class. Please refer the below code snippet and sample for reference. In this sample , Export button click has been hooked with the event QueryImportExportCellInfo.

CodeSnippet[c#]:

private void Export_Click(object sender, System.EventArgs e)

              {

                     Syncfusion.GridExcelConverter.GridExcelConverterControl gecc = new Syncfusion.GridExcelConverter.GridExcelConverterControl();

 

                     SaveFileDialog saveFileDialog = new SaveFileDialog();

                     saveFileDialog.Filter = "Files(*.xls)|*.xls";

                     saveFileDialog.DefaultExt = ".xls";

            gecc.QueryImportExportCellInfo += gecc_QueryImportExportCellInfo;

                     if(saveFileDialog.ShowDialog() == DialogResult.OK)

                     {

                           gecc.GridToExcel(this.gridDataBoundGrid1.Model, saveFileDialog.FileName,

                                  Syncfusion.GridExcelConverter.ConverterOptions.RowHeaders);           

                           if(MessageBox.Show("Do you wish to open the xls file now?", "Export to Excel", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)

                           {

                                  Process proc = new Process();

                                  proc.StartInfo.FileName = saveFileDialog.FileName;

                                  proc.Start();

                           }

                     }

          

              }

 

        void gecc_QueryImportExportCellInfo(object sender, GridImportExportCellInfoEventArgs e)

        {

            if (e.ColIndex > 0 && e.RowIndex > 0 && (this.gridDataBoundGrid1.Binder.InternalColumns[e.ColIndex-1].HeaderText == "CustomerID"))

            {

                //now the column name with CustomerID has been identified.

 

            }

 

        }

 

Sample:

http://www.syncfusion.com/downloads/support/directtrac/118359/CS-1568472712.zip

Please let us know if you have any other concerns.

 

Thanks & Regards,

AL.Solai.

 


CONFIRMATION

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.

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

;