Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
345
Formatting Dates and Currency for export
posted

I have a WebDataGrid that I'm exporting to Excel using the WebExcelExporter.  The grid contains an Amount field and 2 Date fields.  I have been trying to format those columns.  The main export function has these lines:

            wgReportExcelExporter.DisableCellValueFormatting = true;
            wgReportExcelExporter.Export(wgReport);

I also have a function which handles OnGridFieldCaptionExported, in which I am attempting to format the columns like this:

if (String.Compare(e.GridCell.FieldKey, "Total", true) == 0)
   e.Worksheet.Columns[e.CurrentColumnIndex].CellFormat.FormatString = "#,##0.00";
else if (e.GridCell.FieldKey.IndexOf("Date") >= 0)
   e.Worksheet.Columns[e.CurrentColumnIndex].CellFormat.FormatString = "m/d/yyyy";

They both have problems.  The Total field will ONLY format numbers in the thousands - once the numbers reach 1,000,000.00 the formatting no longer works.  (I have tried using a FormatString of "#,###,##0.00" to no avail.)

The two date fields APPEAR to be formatted - if you open the Excel file and click on the cell, the Category is correctly listed as "Date".  However, if you attempt to sort by the column it is apparent that the value is still being perceived as a String by Excel.  (You can only sort "A to Z", not "Oldest to Newest".)  If I "edit" the cell by clicking the enter button (I do NOT change the value, just hit enter) then it "becomes" a date instead of a string.

What am I missing here??

Parents Reply Children