Export to pdf/excel datetime column issue

4 posts, 1 answers
  1. Jacob
    Jacob  avatar
    40 posts
    Member since:
    Apr 2016

    Posted 27 Dec 2016 Link to this post

    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

  2. Answer
    Lance | Tech Support Engineer, Sr.
    Admin
    Lance | Tech Support Engineer, Sr. avatar
    255 posts

    Posted 27 Dec 2016 Link to this post

    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.
  3. Jacob
    Jacob  avatar
    40 posts
    Member since:
    Apr 2016

    Posted 28 Dec 2016 in reply to Lance | Tech Support Engineer, Sr. Link to this post

    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!

  4. Jacob
    Jacob  avatar
    40 posts
    Member since:
    Apr 2016

    Posted 28 Dec 2016 in reply to Lance | Tech Support Engineer, Sr. Link to this post

    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

Back to Top