Hello,
I am able to export the data to excel fine. But I am not able to set Excel styles using code or using Format Settings & Binding.
I have tried the following code (in DataPresenterExcelExporter_CellExporting ), but it fails as I am binding to the style resource.
Setter bgSetter = cellStyle.Setters.Where(s => s is Setter && (s as Setter).Property.Name.Equals("Background")). FirstOrDefault() as Setter;
if (bgSetter != null) { e.FormatSettings.FillPatternForegroundColor = (bgSetter.Value as SolidColorBrush).Color; } The problem is, since I am data binding using Setter (<Setter Property="Background" Value="{Binding Path=DataItem.DisplayNameBackgroundColor}" /> ), the value is not soldcolorbrush and the code above is throwing an error.I also tried using the following code in xaml, but it also did not work:
<igExcelExporter:FormatSettings BorderColor="{Binding Path=DataItem.BackgroundColor}" ></igExcelExporter:FormatSettings>I would appreciate your assistant. Also, what is the best / recommended way to export to excel without duplicate DataPresenter Styles?Regards,Sandy
Hi Sandy,
Thank you for your reply. I have been looking into your question and this binding expression will not work in this scenario. My suggestion is to handle the ‘RecordExporting’ event of the DataPresenterExcelExporter and change the Format Setting of every record regarding its underlying data like e.g.:
void exporter_RecordExporting(object sender, RecordExportingEventArgs e)
{
if(((e.Record as DataRecord).DataItem as Car).BasePrice > 25000)
e.FormatSettings.FillPatternBackgroundColor = Colors.Red;
}
where ‘Car’ is the type of your underlying data item.
Let me know, if you need any further assistance on this matter.
Hi Yanko,
I have looked at the sample solution. I am able to export the color if I use the same syntax as sample. But I am trying to bind the color to a property of the object. Please let me know if this is possible.
<igExcelExporter:FormatSettings FillPatternBackgroundColor="{Binding Path=DataItem.FundNameBackgroundColor}"></igExcelExporter:FormatSettings>
Here is how I am binding the grid:
<igDP:XamDataGrid DataSource="{Binding MyItems}" Name="xamDataGrid1" HorizontalAlignment="Center" VerticalAlignment="Top" >
Is it possible to bind the Excel export to a Field instead of hard-coding it?
Great Thank you. The sample looks like what I am looking for. I will look at it and let you know if I need any further assistance.
Thank you,
Sandy
Hello Sandy,
I am just checking if you require any further assistance on the matter.
I have been looking into your question and I can suggest you look in the ‘Custom Excel Export Cell Styling’ sample in our Samples Browser :
xamDataGrid -> Style -> Custom Excel Export Cell Styling