Reputation: 14272
I have a DevExpress WPF grid (version 9.3). When I export to excel, it has horrible additional rows* that completely mess up excel's functionality such as auto filter.
I've been trying to make sense of the documentation and I think that the solution may lie in setting TableView.PrintCellStyle somehow. But it's really not clear.
I am using the TableView.ExportToXls(string path); method.
Is there a quick way of switching off this behaviour and getting a working xls file?
*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.
EDIT: @DmitryG - I have tried this and now, instead of three lines I now get two. 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.
Anything else I can try?
EDIT 2: Have tried the value converter approach. Getting the same additional row.
Worst case, is there anyway of excluding these columns from the export?
Upvotes: 1
Views: 5364
Reputation: 499
DevExpress has significantly improved the export engine in the latest version 14.2 and now the issue should be solved. Please refer to the following help article for more information:
Upvotes: 1
Reputation: 14272
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.
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. That caught me out for a minute.
Upvotes: 0
Reputation: 17848
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:
<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.
P.S. This problem is absent in the latest versions.
Upvotes: 1