I have formatted couple of Columns within the XAMDataGrid using the following Feature
<Style TargetType="{x:Type igEditors:XamNumericEditor}"> <Setter Property="Mask" Value="nnn,nnn,nnn,nnn.nn"/> <Setter Property="NullText" Value="-" /> </Style>
However when I export the Grid to Excel, the formatting of number is lost for e.g. the comma's go missing. Also huge numbers like 150000000000 are displayed as 1.5E+11. Numbers with decimal places as XXX.00 are displayed as XXX. When we manually change the format on the excelsheet to number, the value displayed is as desired.
I am not able to manually export each row and each column as the Grid might have grouping which we wish to have in the same format while export to excel.
Can you please help me with this?
Thank you for the example.
Question was regarding style/state of grid based on DataTrigger! Can styles from data triggers be extracted like you did with cell styles? Can you show it with example.
Hi Abbas,
Attached you can find the sample demonstrating manually exporting styles to excel. Please let me know if you have any furthered questions.
I see your point; waiting for the sample.
Hi,
About your second questions if you are talking for any specific state like specific color in the field then you should export it manually. For example need to handle the CellExporting event and set the appropriate style for it.
Something like this:
void exporter_CellExporting(object sender, CellExportingEventArgs e)
{
Style celllStyle = e.Field.Settings.CellValuePresenterStyle;
if (celllStyle == null && e.Field.Tag != null)
celllStyle = (e.Field.Tag as LabelPresenter).Style;
Setter bgSetter = celllStyle.Setters.Where(s => s is Setter && (s as Setter).Property.Name.Equals("Background")).FirstOrDefault() as Setter;
Setter fgSetter = celllStyle.Setters.Where(s => s is Setter && (s as Setter).Property.Name.Equals("Foreground")).FirstOrDefault() as Setter;
if (bgSetter != null && fgSetter != null)
e.FormatSettings.FontColor = (fgSetter.Value as SolidColorBrush).Color;
e.FormatSettings.FillPatternForegroundColor = (bgSetter.Value as SolidColorBrush).Color;
}
Just you need to get the correct style and set to a tag or wherever is appropriate for you. I will prepare a sample for you demonstrating a cell style exporting. Let me know if you have any furthered questions.
Second question still is kind of unanswered. If styling of grid is based on data triggers; how that state (styles) is exported in excel as is? Can you build a sample project in which your records have background and foreground based on some data triggers. Based on Data; grid will get styles and that needs to be exported.