This is a migrated thread and some comments may be shown as answers.

Export ExcelML Format date to a culture

5 Answers 83 Views
Grid
This is a migrated thread and some comments may be shown as answers.
adam
Top achievements
Rank 1
adam asked on 25 Aug 2011, 03:50 PM
Hi 

i'm exporting a radgrid and trying to format the date to a culture e.g en-us, en-gb.

i've looked at http://www.telerik.com/help/aspnet-ajax/grid-excelml-export.html

but this only allows me to specify shortdate, general date etc

what i want is to display it in the export as follows

en-us - 8/24/2011
en-gb - 24/8/2011

i have formatted it in the radgrid by setting the culture on the page_load

System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(siteCulture);
RadGrid1.Rebind(); 

as i understand from http://www.telerik.com/community/forums/aspnet-ajax/grid/exportsettings-api.aspx

The export gets the data from the db and not the radgrid, so the format in the db is shown, is that right?

i am using onNeedDataSource to populate my radgrid

my current code for export cell styles is:

protected void RadGrid1_ExcelMLExportRowCreated(object source, GridExportExcelMLRowCreatedArgs e)
    {
        e.Row.Cells.GetCellByName("ItemCreatedWhen").StyleValue = "dateStyle";
    }
    
    protected void RadGrid1_ExcelMLExportStylesCreated(object source, GridExportExcelMLStyleCreatedArgs e)
    {
        foreach (StyleElement style in e.Styles)
        {
            switch (style.Id)
            {
                case "headerStyle":
                    style.FontStyle.Bold = true;
                    break;
                case "itemStyle":
                    style.InteriorStyle.Color = System.Drawing.Color.White;
                    style.InteriorStyle.Pattern = Telerik.Web.UI.GridExcelBuilder.InteriorPatternType.Solid;
                    break;
                case "alternatingItemStyle":
                    style.InteriorStyle.Color = System.Drawing.Color.LightBlue;
                    style.InteriorStyle.Pattern = Telerik.Web.UI.GridExcelBuilder.InteriorPatternType.Solid;
                    break;
                    
            }
            
        }
        StyleElement myStyle = new StyleElement("dateStyle");
        myStyle.NumberFormat.FormatType = NumberFormatType.ShortDate;
        myStyle.FontStyle.Bold = true;
        e.Styles.Add(myStyle);    
         
    }

how do i format the date as i want based on culture?

also the background colors i'm applying do not get added to the A column in the excel, why is this?

Thanks

Adam


5 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 25 Aug 2011, 08:05 PM
Hello,
please search e.Cell.Style["mso-number-format"] = @"mm\/dd\/yyyy" in below link.
 Word/Excel export
or
set culture for radgrid before you export.

Thanks,
Jayesh Goyani
0
adam
Top achievements
Rank 1
answered on 26 Aug 2011, 09:45 AM

Hi Jayesh

Did you read my post? i'm exporting ExcelML not word/excel

also i have set the culture of the radgrid using on page_load with

System.Globalization.CultureInfo(siteCulture);
RadGrid1.Rebind(); 

this formats its as it should be for the radgrid, is this not the correct way?



0
Jayesh Goyani
Top achievements
Rank 2
answered on 26 Aug 2011, 09:56 AM
Hello,

Yes i already your post but i say that before you export set this culture.
or in addition also set this culture in Grid_prerender event also.
protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
        {
            if (e.CommandName == Telerik.Web.UI.RadGrid.ExportToExcelCommandName ||
                e.CommandName == Telerik.Web.UI.RadGrid.ExportToWordCommandName ||
                e.CommandName == Telerik.Web.UI.RadGrid.ExportToCsvCommandName)
            {
                ConfigureExport();
            }
        }
      
        public void ConfigureExport()
        {
            // Set Culture here
        }


or also  check  ExportOutput...

protected void RadGrid1_GridExporting(object source, GridExportingArgs e)
{
    switch (e.ExportType)
    {
        case ExportType.Excel:
            //e.ExportOutput value    
            break;
        case ExportType.ExcelML:
            //e.ExportOutput value    // check here again your date is in which format.
            break;
       

    }
}



Thanks,
Jayesh Goyani
0
adam
Top achievements
Rank 1
answered on 26 Aug 2011, 09:59 AM
ok but in 

case ExportType.ExcelML:
            //e.ExportOutput value    // check here again your date is in which format.
            break;

how do i format the date to a culture in ExcelML
0
Jayesh Goyani
Top achievements
Rank 2
answered on 26 Aug 2011, 10:08 AM
Hello,

String Strtemp = e.ExportOutput.value;

then  please check date format in strTemp.

i giving way to find the issue in your code.
note : its not a solution

Thanks,
Jayesh Goyani
Tags
Grid
Asked by
adam
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
adam
Top achievements
Rank 1
Share this question
or