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.
Unfortunately, activation email could not send to your email. Please try again.

GridExcelExport custom date format

Thread ID:

Created:

Updated:

Platform:

Replies:

112442 Sep 23,2013 05:59 PM Sep 25,2013 05:52 AM ASP.NET Web Forms (Classic) 1
loading
Tags: GridGroupingControl
Jo Scothern
Asked On September 23, 2013 05:59 PM

We have a function that takes a dataset and exports it to excel using the GridExcelExport function. The problem we are having is that this is automatically converting the date format in excel to mm/dd/yyyy

We need to be able to specify the format that this comes out.

The code that we are using looks like this:

public static void ExportToExcel(this DataSet datastring filename)
	{
		GridGroupingControl syncGrid = new GridGroupingControl();
		syncGrid.DataSource = data.Tables[0];
		GridExcelExport gridExcelExport = new GridExcelExport(syncGridfilename + ".xls");
 
		gridExcelExport.ExportNestedTable = true;
		gridExcelExport.Export();
	}

Regards
Jo

Hariharan J V [Syncfusion]
Replied On September 25, 2013 05:52 AM

Hi Jo,
 
Thank you for using Syncfusion products.

Your requirement can be achieved by customizing the export cell data format in FormatExcelCellHandler event. Please refer to the following code snipptes:

[Default.aspx.cs]
protected void Button1_Click(object sender, EventArgs e)
{
GridExcelExport excel = new GridExcelExport(this.GridGroupingControl1, "excel.xls");
excel.ExportNestedTable = true;
//Exporting event
excel.FormatExcelCellHandler += new ExportExcelCellHandler(excel_FormatExcelCellHandler);
excel.Export();
}

void excel_FormatExcelCellHandler(object sender, ExcelExportEventArgs e)
{
if (e.RowElement.IsRecord() && e.ExcelCell.Column == 5) // condition to check the record and column as 5th column(Date column)
{
// set the format for specified cell data.
e.ExcelCell.Cells[0].NumberFormat = "m/d/yyyy";
}}

For your convenience, we have prepared a simple sample to demonstrate this and the same can be downloaded from the below link.

Sample: www.syncfusion.com/downloads/support/directtrac/general/export-1432353488.zip

Please let us know if you need any further assistance.

Regards,
Hariharan J.V.


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.

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.

;