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

Export to pdf/excel datetime column issue

3 Answers 192 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jacob
Top achievements
Rank 1
Jacob asked on 27 Dec 2016, 11:06 AM

Dear Telerik support,

My datetime columns arebehaving just the same as you can seein your article here

http://docs.telerik.com/devtools/wpf/controls/radgridview/export/how-to/export-datetime

Then i tried the given solution,but although the event is being called and the Format being attributed with the correct format, the solution doesn't not working for me. My datetime columns cells show as #########

Can you please check my code and see if i am missing something?

private void CustomGridview_ElementExportingToDocument(object sender, GridViewElementExportingToDocumentEventArgs e)
{
    if (e.Element == ExportElement.Cell)
    {
        var cellExportingArgs = e as GridViewCellExportingEventArgs;
        var parameters = cellExportingArgs.VisualParameters as GridViewDocumentVisualExportParameters;
        if (cellExportingArgs.Column.GetType() == typeof(GridViewDataColumn))
        {
            if (((GridViewDataColumn)cellExportingArgs.Column).DataFormatString == "d")
            {
                parameters.Style = new CellSelectionStyle()
                {
                    Format = new CellValueFormat(CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern)
                };
            }
            if (((GridViewDataColumn)cellExportingArgs.Column).DataFormatString == "g")
            {
                parameters.Style = new CellSelectionStyle()
                {
                    Format = new CellValueFormat(CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern + " " + CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern)
                };
            }
        }
    }
}

Thank you

3 Answers, 1 is accepted

Sort by
0
Accepted
Lance | Manager Technical Support
Telerik team
answered on 27 Dec 2016, 08:02 PM
Hello Jacob,

Can you increase the spreadsheet's column width and see if the "#####" changes into the desired output once there is enough space for the content?

I suspect your formatting is working as expected, rather I think you're seeing a known issue where Excel does this for cells with text content wider than available space.

Let us know if this resolves the issue.

Regards,
Lance | Tech Support Engineer, Sr.
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Jacob
Top achievements
Rank 1
answered on 28 Dec 2016, 05:43 PM

Hello Lance,

That actually makes a lot of sense, although I am having the same issue for the pdf as well.

but then this leads me to another issue which I have already opened

http://www.telerik.com/forums/exporting-to-pdf-column-width-issue

once the width is wider, this problem might be solved!

0
Jacob
Top achievements
Rank 1
answered on 28 Dec 2016, 05:46 PM

I tested on EXCEL and indeed that was the problem! Ok, then I just need that other case to be solved and I am done

Thank you

Tags
GridView
Asked by
Jacob
Top achievements
Rank 1
Answers by
Lance | Manager Technical Support
Telerik team
Jacob
Top achievements
Rank 1
Share this question
or