Hello,
I am exporting my xamdatagrid with Infragistics.Windows.DataPresenter.ExcelExporter.
I have 6 decimal columns in my datagrid and some string columns.
In 3 of decimal columns I show them in xamdatagrid with the style below to show numbers like that;
453653.00 as 453.653 with no zeros and thousands seperator as you notice
<Style x:Key="DecimalStyleMiktar" TargetType="{x:Type igEditors:XamCurrencyEditor}"> <Setter Property="Format" Value="#,###"/> </Style>
<Style x:Key="DecimalStyleMiktar" TargetType="{x:Type igEditors:XamCurrencyEditor}">
<Setter Property="Format" Value="#,###"/>
</Style>
Other 3 decimal columns with the format below
6.435543 as 6,43
0.23432 as 0.23
7.00 as 7
<Style x:Key="DecimalStyle" TargetType="{x:Type igEditors:XamCurrencyEditor}"> <Setter Property="Format" Value="N"/> </Style>
<Style x:Key="DecimalStyle" TargetType="{x:Type igEditors:XamCurrencyEditor}">
<Setter Property="Format" Value="N"/>
When I exporting this decimalstyles to excel, I use the below code. But Is there any single format that
combine my two format("#,###" and "#,##0.00"; ) into one? Or Is there any easier , cleaner way to set number format in columns in the excel?
Thanks
for (int i = 0; i < tempGrid.FieldLayouts[0].Fields.Count; i++) { if (tempGrid.FieldLayouts[0].Fields[i].Settings.EditorStyle != null) { if (tempGrid.FieldLayouts[0].Fields[i].Settings.EditorStyle.Setters.OfType<Setter>().FirstOrDefault(setter => setter.Property.Name == "Format").Value.ToString() == "#,###") worksheet.Columns[i].CellFormat.FormatString = "#,###"; else if (tempGrid.FieldLayouts[0].Fields[i].Settings.EditorStyle.Setters.OfType<Setter>().FirstOrDefault(setter => setter.Property.Name == "Format").Value.ToString() == "N") worksheet.Columns[i].CellFormat.FormatString = "#,##0.00"; } }
for (int i = 0; i < tempGrid.FieldLayouts[0].Fields.Count; i++)
{
if (tempGrid.FieldLayouts[0].Fields[i].Settings.EditorStyle != null)
if (tempGrid.FieldLayouts[0].Fields[i].Settings.EditorStyle.Setters.OfType<Setter>().FirstOrDefault(setter => setter.Property.Name == "Format").Value.ToString() == "#,###")
worksheet.Columns[i].CellFormat.FormatString = "#,###";
else if (tempGrid.FieldLayouts[0].Fields[i].Settings.EditorStyle.Setters.OfType<Setter>().FirstOrDefault(setter => setter.Property.Name == "Format").Value.ToString() == "N")
worksheet.Columns[i].CellFormat.FormatString = "#,##0.00";
}
I have been looking into your issue and I have managed to achieve the functionality that you would like handling the ‘CellExporting’ event of the DataPresenterExcelExporter and in its body I set the ‘FormatString’ property of every cell according to the ‘Format’ property of its editor in XamDataGrid. I am sending you a sample application(DataGridExportToExcelStylesColumns.zip) that shows that functionality.
If you need any further assistance on this matter, feel free to ask.
thanks Yanko, It is working :)
I have a extra question.
In my xamdatagrid I have a unboundfield like below. How can I set AllowClipboardOperations="Copy" ?
I am trying to set in XamDataGrid.FieldLayoutSettings but It doesnt work. I guess the reason is textblocks in stackpanel. Is there any solution that provides AllowClipboardOperations="Copy" function?
<igDP:UnboundField> <igDP:UnboundField.Settings> <igDP:FieldSettings> <igDP:FieldSettings.LabelPresenterStyle> <Style TargetType="{x:Type igDP:LabelPresenter}" > <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igDP:LabelPresenter}"> <StackPanel Orientation="Vertical"> <TextBlock Text="Test" ></TextBlock> <TextBlock Text="Test-2" ></TextBlock> </StackPanel> </ControlTemplate> </Setter.Value> </Setter> </Style> </igDP:FieldSettings.LabelPresenterStyle> <igDP:FieldSettings.CellValuePresenterStyle> <Style TargetType="{x:Type igDP:CellValuePresenter}" > <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}"> <StackPanel Orientation="Vertical"> <TextBlock Text="{Binding Path=DataItem.NAME}" ></TextBlock> <TextBlock Text="{Binding Path=DataItem.SECOND}" ></TextBlock> </StackPanel> </ControlTemplate> </Setter.Value> </Setter> </Style> </igDP:FieldSettings.CellValuePresenterStyle> </igDP:FieldSettings> </igDP:UnboundField.Settings> </igDP:UnboundField>
<igDP:UnboundField>
<igDP:UnboundField.Settings>
<igDP:FieldSettings>
<igDP:FieldSettings.LabelPresenterStyle>
<Style TargetType="{x:Type igDP:LabelPresenter}" >
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type igDP:LabelPresenter}">
<StackPanel Orientation="Vertical">
<TextBlock Text="Test" ></TextBlock>
<TextBlock Text="Test-2" ></TextBlock>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</igDP:FieldSettings.LabelPresenterStyle>
<igDP:FieldSettings.CellValuePresenterStyle>
<Style TargetType="{x:Type igDP:CellValuePresenter}" >
<ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}">
<TextBlock Text="{Binding Path=DataItem.NAME}" ></TextBlock>
<TextBlock Text="{Binding Path=DataItem.SECOND}" ></TextBlock>
</igDP:FieldSettings.CellValuePresenterStyle>
</igDP:FieldSettings>
</igDP:UnboundField.Settings>
</igDP:UnboundField>
I have been looking into your post and I have modified the provided code in order to achieve the desired functionality. I have handled the ‘ExecutedEvent’ of the XamDataGrid where I am checking where the ‘Copy’ operation is executed and the desired field’ cell is active. I am sending you a sample application(DataGridCopy.zip) that shows this functionality.
If you need any further assistance, feel free to ask.
It works. thank you Yanko for your help.