Hi,
I am using Xamdatagrid, WPF, Viewmodel. While i am trying to export the xamdatagrid data into excel im missing the column header name. i am attaching the excel screen shot.
Hello Kannabiran,
Thank you for your post. I have been looking through it and I suggest you may see our online help:
http://help.infragistics.com/NetAdvantage/WPF/?page=xamDataGrid_Exporting_to_Excel.html
You can also check an excel export example in the WPF Samples Browser version 2013 volume 1 under xamDataGrid / Editing and Selection / Export to Excel.
In order further to investigate your issue, can you provide a sample and more information about the version of the product you are using?
Looking forward for your reply.
Sincerely,
Svetla
I am checking if this is still an issue for you.
If you require any further assistance please do not hesitate to ask.
Hi Svetla,
We have gone through your thread, we tried that also still its not working. since the exporter function is the inbuilt thing we unable to invetigate more on this. My code is below.
<UserControl x:Class="XXX.Emt.UI.Controls.Wpf.WorkOrderHistoryView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:igWindows="clr-namespace:Infragistics.Windows.Controls;assembly=Infragistics3.Wpf.v9.2" xmlns:igDataPresenter="clr-namespace:Infragistics.Windows.DataPresenter;assembly=Infragistics3.Wpf.DataPresenter.v9.2" xmlns:Wpf="clr-namespace:XXX.Emt.UI.Controls.Wpf"> <UserControl.Resources> <LinearGradientBrush x:Key="cellBrush" MappingMode="RelativeToBoundingBox" EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FFFFF9DB"/> <GradientStop Color="#FFFFEFA9" Offset="1"/> </LinearGradientBrush> <Style x:Key="headerStyle" TargetType="{x:Type igDataPresenter:CellValuePresenter }"> <Setter Property="Background" Value="{StaticResource cellBrush}" /> </Style> <Style TargetType="{x:Type igWindows:CarouselListBoxItem}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igWindows:CarouselListBoxItem}"> <Grid x:Name="itemContentHolder" HorizontalAlignment="Center" VerticalAlignment="Top"> <ContentControl x:Name="itemContent" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}"/> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsSelected" Value="True"> <Setter Property="Background" TargetName="itemContentHolder"> <Setter.Value> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FFFFF9CD" Offset="0"/> <GradientStop Color="#FFFFE591" Offset="1"/> <GradientStop Color="#FFFFD648" Offset="0.5"/> </LinearGradientBrush> </Setter.Value> </Setter> </Trigger> <Trigger Property="IsSelected" Value="False"> <Setter Property="Background" TargetName="itemContentHolder"> <Setter.Value> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FFFFF9CD" Offset="0"/> <GradientStop Color="#FF848484" Offset="1"/> <GradientStop Color="#FFCECECE" Offset="0.5"/> </LinearGradientBrush> </Setter.Value> </Setter> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <DataTemplate x:Key="SimpleDataTemplate"> <Grid Width="120"> <Grid.RowDefinitions> <RowDefinition Height="25"/> <RowDefinition Height="40"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition /> <ColumnDefinition /> </Grid.ColumnDefinitions> <Rectangle Stroke="Gray" StrokeDashCap="Square" StrokeThickness="1.5" Grid.RowSpan="2" Grid.ColumnSpan="2" > </Rectangle> <TextBlock Margin="8,8,0,0" Grid.ColumnSpan="2" FontWeight="Bold" FontSize="12" Text="{Binding MetrologyId}" HorizontalAlignment="Left" VerticalAlignment="Top" TextWrapping="Wrap"/> <TextBlock Margin="8,8,0,0" Grid.Row="1" Grid.ColumnSpan="2" Text="{Binding Description}" TextWrapping="Wrap" HorizontalAlignment="Left"/> <Image HorizontalAlignment="Right" Opacity="0.3" Panel.ZIndex="-1" Grid.ColumnSpan="2" Grid.RowSpan="2" Width="48" Height="48" Source="/XXX.Emt.UI.Controls.Wpf;component/Image/Microscope grey.png" Stretch="Fill"/> </Grid> </DataTemplate> </UserControl.Resources> <Grid> <Grid.RowDefinitions> <RowDefinition Height="130"></RowDefinition> <RowDefinition Height="*"></RowDefinition> </Grid.RowDefinitions> <Wpf:CarouselSelector Margin="0,5,0,0" ItemsSource="{Binding EquipmentCollection}" SelectedItem="{Binding ActiveEquipment, Mode=TwoWay}" ItemContainerGenerationMode="PreLoad" SelectionChanged="XamCarouselListBox_SelectionChanged" ItemTemplate="{StaticResource SimpleDataTemplate}" ItemCount="5" SelectedItemPosition="1"> </Wpf:CarouselSelector> <igDataPresenter:XamDataGrid x:Name="workOrderHistoryGrid" Grid.Row="1" DataSource="{Binding Path=WorkOrderHistoryViewModel.WorkOrderHistoryEntryCollection}"> <igDataPresenter:XamDataGrid.FieldLayoutSettings> <igDataPresenter:FieldLayoutSettings HighlightAlternateRecords="True" HeaderPrefixAreaDisplayMode="FieldChooserButton" AutoGenerateFields="False" ExpansionIndicatorDisplayMode="Default" FixedFieldUIType="None" /> </igDataPresenter:XamDataGrid.FieldLayoutSettings> <igDataPresenter:XamDataGrid.FieldLayouts> <igDataPresenter:FieldLayout Key="EquipmentHeader"> <igDataPresenter:FieldLayout.Fields> <igDataPresenter:Field Name="InstrumentId" Label="Instrument Id" > <igDataPresenter:Field.Settings> <igDataPresenter:FieldSettings CellValuePresenterStyle="{StaticResource headerStyle}" AllowEdit="False"/> </igDataPresenter:Field.Settings> </igDataPresenter:Field> <igDataPresenter:Field Name="Description" Label="Description" Width="Auto"> <igDataPresenter:Field.Settings> <igDataPresenter:FieldSettings CellValuePresenterStyle="{StaticResource headerStyle}" AllowEdit="False"/> </igDataPresenter:Field.Settings> </igDataPresenter:Field> <igDataPresenter:Field Name="WorkOrderHistoryEntry" Label="Work Order HistoryEntry"/> </igDataPresenter:FieldLayout.Fields> </igDataPresenter:FieldLayout> <igDataPresenter:FieldLayout Key="WorkOrderHistory"> <igDataPresenter:FieldLayout.Fields> <igDataPresenter:Field Name="MetrologyId" Label="Instrument Id" Visibility="Collapsed"> <igDataPresenter:Field.Settings> <igDataPresenter:FieldSettings AllowEdit="False"/> </igDataPresenter:Field.Settings> </igDataPresenter:Field> <igDataPresenter:Field Name="Description" Label="Description" Visibility="Collapsed" > <igDataPresenter:Field.Settings> <igDataPresenter:FieldSettings AllowEdit="False"/> </igDataPresenter:Field.Settings> </igDataPresenter:Field> <igDataPresenter:Field Name="LongDescription" Label="Long Description" Visibility="Collapsed" > <igDataPresenter:Field.Settings> <igDataPresenter:FieldSettings AllowEdit="False"/> </igDataPresenter:Field.Settings> </igDataPresenter:Field> <igDataPresenter:Field Name="Organization" Label="Organization"> <igDataPresenter:Field.Settings> <igDataPresenter:FieldSettings AllowEdit="False"/> </igDataPresenter:Field.Settings> </igDataPresenter:Field> <igDataPresenter:Field Name="ParentId" Label="Parent Id"> <igDataPresenter:Field.Settings> <igDataPresenter:FieldSettings AllowEdit="False"/> </igDataPresenter:Field.Settings> </igDataPresenter:Field> <igDataPresenter:Field Name="CostCenter" Label="Cost Center"> <igDataPresenter:Field.Settings> <igDataPresenter:FieldSettings AllowEdit="False"/> </igDataPresenter:Field.Settings> </igDataPresenter:Field> <igDataPresenter:Field Name="DateRequired" Label="Date Required"> <igDataPresenter:Field.Settings> <igDataPresenter:FieldSettings AllowEdit="False"/> </igDataPresenter:Field.Settings> </igDataPresenter:Field> <igDataPresenter:Field Name="WorkOrderNumber" Label="Work Order Number"> <igDataPresenter:Field.Settings> <igDataPresenter:FieldSettings AllowEdit="False"/> </igDataPresenter:Field.Settings> </igDataPresenter:Field> <igDataPresenter:Field Name="ReportedBy" Label="Reported By"> <igDataPresenter:Field.Settings> <igDataPresenter:FieldSettings AllowEdit="False"/> </igDataPresenter:Field.Settings> </igDataPresenter:Field> <igDataPresenter:Field Name="WorkStatus" Label="Work Status"> <igDataPresenter:Field.Settings> <igDataPresenter:FieldSettings AllowEdit="False"/> </igDataPresenter:Field.Settings> </igDataPresenter:Field> <igDataPresenter:Field Name="WorkOrderType" Label="Work Order Type"> <igDataPresenter:Field.Settings> <igDataPresenter:FieldSettings AllowEdit="False"/> </igDataPresenter:Field.Settings> </igDataPresenter:Field> <igDataPresenter:Field Name="WorkType" Label="Work Type"> <igDataPresenter:Field.Settings> <igDataPresenter:FieldSettings AllowEdit="False"/> </igDataPresenter:Field.Settings> </igDataPresenter:Field> <igDataPresenter:Field Name="WorkOrderDescription" Label="Work Order Description"> <igDataPresenter:Field.Settings> <igDataPresenter:FieldSettings AllowEdit="False"/> </igDataPresenter:Field.Settings> </igDataPresenter:Field> <igDataPresenter:Field Name="RequestDate" Label="Request Date"> <igDataPresenter:Field.Settings> <igDataPresenter:FieldSettings AllowEdit="False"/> </igDataPresenter:Field.Settings> </igDataPresenter:Field> <igDataPresenter:Field Name="CompleteDate" Label="Complete Date"> <igDataPresenter:Field.Settings> <igDataPresenter:FieldSettings AllowEdit="False"/> </igDataPresenter:Field.Settings> </igDataPresenter:Field> <igDataPresenter:Field Name="EnteredBy" Label="Entered By"> <igDataPresenter:Field.Settings> <igDataPresenter:FieldSettings AllowEdit="False"/> </igDataPresenter:Field.Settings> </igDataPresenter:Field> <igDataPresenter:Field Name="MaintenanceCost" Label="Maintenance Cost"> <igDataPresenter:Field.Settings> <igDataPresenter:FieldSettings AllowEdit="False"/> </igDataPresenter:Field.Settings> </igDataPresenter:Field> </igDataPresenter:FieldLayout.Fields> </igDataPresenter:FieldLayout> </igDataPresenter:XamDataGrid.FieldLayouts> </igDataPresenter:XamDataGrid> </Grid></UserControl>
namespace XXX.Emt.UI.ViewModel{ using System.IO; using System.Windows; using Infragistics.Excel; using Infragistics.Windows.DataPresenter; using Infragistics.Windows.DataPresenter.ExcelExporter;
/// <summary> /// Excel exporter. /// </summary> public class ExcelExporter { /// <summary> /// Exports the specified <c>xam</c> data grid. /// </summary> /// <param name="xamDataGrid">The <c>xam</c> data grid.</param> /// <param name="fileName">Name of the file.</param> public void Export(XamDataGrid xamDataGrid, string fileName) { if (string.IsNullOrEmpty(fileName)) { return; }
var exporter = new DataPresenterExcelExporter();
try { exporter.Export(xamDataGrid, fileName, WorkbookFormat.Excel2007); } catch (IOException) { MessageBox.Show("Close Excel file before save or save it with a different name.", "EMT - Exporting to Excel", MessageBoxButton.OK, MessageBoxImage.Warning); } } }}
Hello, Kannabiran,
Hello, Kannabiran
Thank you for the provided information. As I looked at your XAML code I found that there are fields that have Visibility set to Collapsed. If a parent field is not visible, it won’t be visible in xamDataGrid and won’t be exported to excel worksheet. If it has children records – they will be visible and will be exported to the excel document.
I have attached a sample application with two FieldLayouts for reference.
If you have more questions, don’t hesitate to ask me.