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; }}
Was a solution for preventing the child rows from being indented when exporting a parent/child hierarchy provided?
HI,
In order to get the CellValuePresenter, you must bring the cell into view.
Here is a sample that does just that.
Dear VinitSankhe,
I have the same problem regarding how to retrieve actual cell style during export.
The problem is, CellValuePresenter object that I get through CellValuePresenter.FromRecordAndField is null. And I can see no explicit way to inspect style properties of the cell value.
The code is like this:
<igDP:XamDataGrid.FieldSettings> <igDP:FieldSettings >
<igDP:FieldSettings.CellValuePresenterStyle> <Style TargetType="{x:Type igDP:CellValuePresenter}"> <Style.Triggers> <DataTrigger Binding="{Binding Path=DataItem.ValidnessByDate}" Value="{x:Static my:ValidnessByDate.Expired}"> <Setter Property="ForegroundStyle"> <Setter.Value> <Style> <Setter Property="TextBlock.Foreground" Value="Red" /> </Style> </Setter.Value> </Setter> </DataTrigger> <DataTrigger Binding="{Binding Path=DataItem.ValidnessByDate}" Value="{x:Static my:ValidnessByDate.ExpiresIn30Days}"> <Setter Property="ForegroundStyle"> <Setter.Value> <Style> <Setter Property="TextBlock.Foreground" Value="Orange" /> </Style> </Setter.Value> </Setter> </DataTrigger> </Style.Triggers> </Style> </igDP:FieldSettings.CellValuePresenterStyle>
presenterExporter.CellExporting += (sender, args) => {var cellValuePresenter = CellValuePresenter.FromRecordAndField(args.Record, args.Field); // null
...
}
Hi Matt, The actual problem is resolved but I am across a new problem now.
My xamdatagrid has parent child relationship (nested records). The nested data grids have exactly same layout as the parent (same fields and same order). Now when I use export funcitonality it exports with parent child layout correctly. But the issue is the child data grid is shifted one cell to the right as below.
For my end users this is annoying. They think that the child grids should not be shifted to the right and also should not have their own headers at all. In fact the excel 2007 hierarchy to expand and collapse the child grids, they like, but not with shifted child grids that have their own headers as below.
What changes should I be doing here to make this happen?
XAML:
Below is my parent and child layout that have two fields that I need. BaseGrid is a user control derived from XamDataGrid class.
<common:BaseGrid TextBlock.Foreground="Black" Background="#FFFFFFE9" FontFamily="Arial" Name="xamDataGrid" > <common:BaseGrid.FieldLayouts> <igDP:FieldLayout Key="parentLayout" > <igDP:FieldLayout.SortedFields> <igDP:FieldSortDescription FieldName="ID" Direction="Descending" /> <igDP:FieldSortDescription FieldName="myEntryTime" Direction="Descending" /> </igDP:FieldLayout.SortedFields> <igDP:FieldLayout.FieldSettings> <igDP:FieldSettings FilterCellEditorStyle="{StaticResource inlineFilterStyle}" GroupByRecordPresenterStyle="{StaticResource BlackGroupRow}" > <igExcelExporter:DataPresenterExcelExporter.ExcelCellFormatSettings> <igExcelExporter:FormatSettings BorderColor="Blue" BorderStyle="Thin" BottomBorderColor="#FF999999" BottomBorderStyle="Thin" FillPattern="Solid" FillPatternBackgroundColor="White" FillPatternForegroundColor="White" FontColor="Black" FontFamily="Arial" FontStrikeout="False" FontStyle="Normal" FontWeight="Normal" FormatString="" Indent="0" LeftBorderColor="#FF999999" LeftBorderStyle="Thin" Locked="True" RightBorderColor="#FF999999" RightBorderStyle="Thin" Rotation="0" ShrinkToFit="False" TopBorderColor="#FF999999" TopBorderStyle="Thin" WrapText="True"> <igExcelExporter:FormatSettings.FontSize> <igWindows:DeviceUnitLength Value="10" UnitType="Point" /> </igExcelExporter:FormatSettings.FontSize> </igExcelExporter:FormatSettings> </igExcelExporter:DataPresenterExcelExporter.ExcelCellFormatSettings>
<igExcelExporter:DataPresenterExcelExporter.ExcelLabelFormatSettings> <igExcelExporter:FormatSettings BorderColor="#FF999999" BorderStyle="Thin" FillPattern="Solid" FillPatternBackgroundColor="#FF8064A2" FillPatternForegroundColor="#FFB2A1C7" FontColor="Black" FontFamily="Arial" FontWeight="Bold" HorizontalAlignment="Left"> <igExcelExporter:FormatSettings.FontSize> <igWindows:DeviceUnitLength Value="10" UnitType="Point" /> </igExcelExporter:FormatSettings.FontSize> </igExcelExporter:FormatSettings> </igExcelExporter:DataPresenterExcelExporter.ExcelLabelFormatSettings> </igDP:FieldSettings> </igDP:FieldLayout.FieldSettings> </igDP:FieldLayout> <igDP:FieldLayout Key="childLayout"> <igDP:FieldLayout.SortedFields> <igDP:FieldSortDescription FieldName="ID" Direction="Descending" /> <igDP:FieldSortDescription FieldName="myEntryTime" Direction="Descending" /> </igDP:FieldLayout.SortedFields> <igDP:FieldLayout.FieldSettings> <igDP:FieldSettings AllowRecordFiltering="False" AllowResize="False"> <igExcelExporter:DataPresenterExcelExporter.ExcelCellFormatSettings> <igExcelExporter:FormatSettings BorderColor="Blue" BorderStyle="Thin" BottomBorderColor="#FF999999" BottomBorderStyle="Thin" FillPattern="Solid" FillPatternBackgroundColor="White" FillPatternForegroundColor="White" FontColor="Black" FontFamily="Arial" FontStrikeout="False" FontStyle="Normal" FontWeight="Normal" FormatString="" Indent="0" LeftBorderColor="#FF999999" LeftBorderStyle="Thin" Locked="True" RightBorderColor="#FF999999" RightBorderStyle="Thin" Rotation="0" ShrinkToFit="False" TopBorderColor="#FF999999" TopBorderStyle="Thin" WrapText="True"> <igExcelExporter:FormatSettings.FontSize> <igWindows:DeviceUnitLength Value="10" UnitType="Point" /> </igExcelExporter:FormatSettings.FontSize> </igExcelExporter:FormatSettings> </igExcelExporter:DataPresenterExcelExporter.ExcelCellFormatSettings>
<igExcelExporter:DataPresenterExcelExporter.ExcelLabelFormatSettings> <igExcelExporter:FormatSettings BorderColor="#FF999999" BorderStyle="Thin" FillPattern="Solid" FillPatternBackgroundColor="#FF8064A2" FillPatternForegroundColor="#FFB2A1C7" FontColor="Black" FontFamily="Arial" FontWeight="Bold" HorizontalAlignment="Left"> <igExcelExporter:FormatSettings.FontSize> <igWindows:DeviceUnitLength Value="10" UnitType="Point" /> </igExcelExporter:FormatSettings.FontSize> </igExcelExporter:FormatSettings> </igExcelExporter:DataPresenterExcelExporter.ExcelLabelFormatSettings> </igDP:FieldSettings> </igDP:FieldLayout.FieldSettings> </igDP:FieldLayout> <igDP:FieldLayout Key="dummy" > </igDP:FieldLayout> </common:BaseGrid.FieldLayouts></common:BaseGrid>
I am just following up on this tread.
Do you need further assistance regarding this case.
Sincerely, Matt Developer Support Engineer