Datagrid to excel不适用于多行标题

时间:2014-02-03 15:23:02

标签: c# wpf excel datagrid

我使用此示例将数据从wpf datagrid http://kidaatlantis.wordpress.com/2013/11/04/data-export-from-datagrid-to-excel-in-wpf/

导出到excel

我的datagrid定义如下:

 <DataGrid Name="InputReportDataGrid"  AutoGenerateColumns="False" CanUserAddRows="false" HeadersVisibility="Column" >
                    <DataGrid.ColumnHeaderStyle>
                        <Style TargetType="Control">
                            <Setter Property="FontSize" Value="10"/>
                        </Style>
                    </DataGrid.ColumnHeaderStyle>
                    <DataGrid.RowStyle>
                        <Style TargetType="Control">
                            <Setter Property="FontSize" Value="10"/>
                        </Style>
                    </DataGrid.RowStyle>
                    <DataGrid.Columns>
                        <!--<DataGridTextColumn Header="RedniBroj" />-->
                        <DataGridTextColumn Header="UCode" Binding="{Binding Path= tblGood.UCode}" />
                        <DataGridTextColumn Header="Good Name" Binding="{Binding Path= tblGood.Name}" />
                        <DataGridTextColumn Header="Measurement&#x0a; Unit" Binding="{Binding Path= tblGood.MeasurementUnit}" />
                        <DataGridTextColumn Header="Amount" Binding="{Binding Path= Amount, Converter={StaticResource moneyConverter}}" />
                        <DataGridTextColumn Header="Input Price" Binding="{Binding Path= InputPrice, Converter={StaticResource moneyConverter}}" />
                        <DataGridTextColumn Header="Input Value" Binding="{Binding Path= InputValue, Converter={StaticResource moneyConverter}}" />
                        <DataGridTextColumn Header="Suggested Price" Binding="{Binding Path= SuggestedPrice, Converter={StaticResource moneyConverter}}" />
                        <DataGridTextColumn Header="Suggested&#x0a; Value" Binding="{Binding Path= SuggestedValue, Converter={StaticResource moneyConverter}}" />
                        <DataGridTextColumn Header="Vat" Binding="{Binding Path= VatBase}" />
                        <DataGridTextColumn Header="Vat Value" Binding="{Binding Path= VatValue, Converter={StaticResource moneyConverter}}" />
                        <DataGridTextColumn Header="Suggested&#x0a; Value&#x0a; Without&#x0a; Vat" Binding="{Binding Path= SuggestedValueWithoutVat, Converter={StaticResource moneyConverter}}" />
                        <DataGridTextColumn Header="RUC" Binding="{Binding Path= SuggestedValueWithoutVat, Converter={StaticResource moneyConverter}}" />
                    </DataGrid.Columns>
                </DataGrid>

现在,当我在datagrid列标题中不使用换行符时,一切正常,数据将按原样导出到excel。但是当我使用换行符时,在我的excel文件中,我的列标题中的每个换行符都被识别为单独的列,因此我有更多的列而不是它应该是,当然,我的数据没有按照它应该排序。有什么建议如何解决这个问题?

0 个答案:

没有答案