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
220
Expot Excel with Background and Foregrodund Color Of Cell
posted

Hi,

I need to export with background and foreground color of the individual cell value presenter. I read somewhere on this forum that we can do this using excel expoter's FormatString property. How exactly? I mean can it differ in color per cell that is getting exported?

On the feature browser there is a sample which formats the excel export but it colors all the cells in  one background color. This is not desired in my case. On my XamDataGrid I have various triggers, data record presenter styles and cell value styles applied. So ultimately what matters to me is individual cell value presenter's Background color property.

How can I set it across to the excel exporter for each cell getting exported?

I tried doing this...

private void exporter_CellExporting(object sender, CellExportingEventArgs e) {
    var dataRecord = dg.GetRecordFromDataItem(e.Record.DataItem, false);
    CellValuePresenter cvp1 = CellValuePresenter.FromRecordAndField(dataRecord, e.Field);
    if (cvp1 != null) {
        e.Record.Cells[0].DataPresenter.Background = cvp1.Background;
    }
}