'How to export a DevExpress PivotGridControl to Excel

I have a button click that attempts to export a DevExpress pivot grid to an excel file however when you open the file in excel or google sheets it zeroes some of the data in the 'Start Time' and 'End Time' cells. Here is the c# code:

private void button_Export_Click(object sender, EventArgs e)
        {            
            var x = new DevExpress.XtraPrintingLinks.CompositeLink();

            if (xtraTabControl1.SelectedTabPage == xtraTabPage_Grid)
            {
                if (saveFileDialog_Report.ShowDialog() == DialogResult.OK)
                {
                    XlsxExportOptionsEx ExportOptions = new XlsxExportOptionsEx();
                    ExportOptions.ExportType = DevExpress.Export.ExportType.WYSIWYG;

                    if (saveFileDialog_Report.FileName.ToLower().EndsWith("xlsx"))
                    {
                        try
                        {
                            pivotGridControl1.ExportToXlsx(saveFileDialog_Report.FileName, ExportOptions);
                        }
                        catch (Exception Ex)
                        {
                            cGlobal.ShowErrorMessage(Ex.Message, "Error");

                        }
                    }


                    if (saveFileDialog_Report.FileName.ToLower().EndsWith("pdf"))
                    {
                        pivotGridControl1.ExportToPdf(saveFileDialog_Report.FileName);
                    }
                }
            }
            else
                cGlobal.ShowInfoMessage("To export a chart please use the print option and then use the export feature within the preview window", "Not Available");
        }   

The data is displayed correctly in the pivot grid for example:

Start Time End Time
07:15 17:00
07:09 17:00

But then one row will be randomly zeroed in excel/ sheets:

Start Time End Time
07:15 17:00
00:00 00:00

I've tried it with XLS and it still zeroes the same rows. Any help would be appreciated.

In the model the start time and end time are brought in as DateTime's.

Edit: The exact same code works when exporting to CSV format.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source