简体   繁体   English

DevExpress WPF Grid导出到excel - 附加行

[英]DevExpress WPF Grid export to excel - additional rows

I have a DevExpress WPF grid (version 9.3). 我有一个DevExpress WPF网格(版本9.3)。 When I export to excel, it has horrible additional rows* that completely mess up excel's functionality such as auto filter. 当我导出到excel时,它有可怕的额外行*,这完全搞乱了excel的功能,如自动过滤器。

在此输入图像描述

I've been trying to make sense of the documentation and I think that the solution may lie in setting TableView.PrintCellStyle somehow. 我一直试图理解文档,我认为解决方案可能在于以某种方式设置TableView.PrintCellStyle But it's really not clear. 但它真的不清楚。

I am using the TableView.ExportToXls(string path); 我正在使用TableView.ExportToXls(字符串路径); method. 方法。

Is there a quick way of switching off this behaviour and getting a working xls file? 有没有一种快速关闭此行为并获得正常工作的xls文件的方法?

*I understand that this is to help with creating a spreadsheet that looks the same as the grid. *我知道这有助于创建与网格相同的电子表格。 Horrible default behaviour - a working spreadsheet is more important than it looking like the UI. 可怕的默认行为 - 工作电子表格比看起来像UI更重要。

EDIT : @DmitryG - I have tried this and now, instead of three lines I now get two. 编辑 :@DmitryG - 我已经尝试了这个,现在,而不是三行我现在得到两个。 Better, but not solved. 更好,但没有解决。

在此输入图像描述

I have also checked the KB article you cited and get the following result: 我还检查了您引用的知识库文章并获得以下结果:

在此输入图像描述

I am using version 9.3.6. 我使用的是9.3.6版。

Anything else I can try? 还有什么我可以尝试的吗?

EDIT 2: Have tried the value converter approach. 编辑2:尝试过值转换器方法。 Getting the same additional row. 获得相同的额外行。

在此输入图像描述

Worst case, is there anyway of excluding these columns from the export? 最坏的情况是,有没有从出口中排除这些列?

DevExpress has significantly improved the export engine in the latest version 14.2 and now the issue should be solved. DevExpress在最新版本14.2中显着改进了导出引擎,现在问题应该得到解决。 Please refer to the following help article for more information: 有关更多信息,请参阅以下帮助文章:

Printing and Exporting 印刷和出口

As far as I can see the problem like yours was already discussed here: Exporting Boolean Values causes Three Merged Rows To Appear for each Row of data . 据我所知,此处已经讨论过像你这样的问题: 导出布尔值会导致每行数据出现三个合并行
The problem solution for version 9.3 was the direct assigning of the GridColumn.EditSettings property: 版本9.3的问题解决方案是直接分配GridColumn.EditSettings属性:

<dxg:GridColumn x:Name="Boolean" FieldName="Boolean">
    <dxg:GridColumn.EditSettings>
        <dxe:CheckEditSettings HorizontalContentAlignment="Center"/>
    </dxg:GridColumn.EditSettings>
</dxg:GridColumn>

Please also review the following KB article: How to change representation of data cells via PrintCellStyle when printing/exporting grid data . 另请查看以下知识库文章: 如何在打印/导出网格数据时通过PrintCellStyle更改数据单元格的表示形式

PS This problem is absent in the latest versions. PS最新版本中没有此问题。

I was still getting the additional rows. 我仍然得到额外的行。 The quickest and easiest way to get around this was to set the EditSettings of the column so it exports 'True' or 'False', export the grid then set the column back to a checkbox. 解决此问题的最快捷,最简单的方法是设置列的EditSettings,使其导出'True'或'False',导出网格,然后将列设置回复选框。

Thusly: 正是如此:

public void ExportGridToExcel()
{
    TableView.Grid.Columns["*FieldName*"].EditSettings = new TextEditSettings();

    TableView.ExportToXls(@"C:\temp\spreadsheet.xls");

    TableView.Grid.Columns["*FieldName*"].EditSettings = new CheckEditSettings();
}

NB It's the fieldname the column is bound to and NOT the column name . NB它的列绑定到字段名 ,而不是列名 That caught me out for a minute. 那抓住了我一会儿。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM