Hi,
We are trying to enhance our product already using Infragistics Controls.
At the moment we are trying to export our grids to Excel or Word but the styles we have defined in the XAML are not being kept/applied when the export happens.
From the help files here http://help.infragistics.com/help/doc/wpf/2012.1/clr4.0/html/xamDataPresenter_Apply_Formats_for_Exporting.html we understood that as the settings where defined in the FieldSettings of the DataPresenter, they should have been applied.
Another issue we are seeing is that the first column is not being exported to excel or word.
I have added a zip file with what we are trying to do and showing the error. Export the tree-grid to excel or word, with the same style.
Hope to hear from you soon.
Thanks
Forecast 5 Dev Team
Hello Forecast Five,
As I looked into your sample application, I've found that it retemplates a style targeting TreeCellValuePresenter and uses converters to style each cell. In that case, I'm afraid to say that you cannot use the way described in the document you linked in your post.And the reason why the first column is not exported is because the texts on the first column is not a value of that cell, but a value of a TextBlock in the customized control template.
In order to make what you want to do possible, you may want to use CellExported event of DataPresenterExcelExporter, get the record data from CellExportedEventArgs's Record property, and implement the same logic as you do in the customized retemplated style.
Similarly, in case of exporting the grid to Word, you should use Infragistics Word library https://es.infragistics.com/help/wpf/word-using-the-ig-word-library instead of DataPresenterWordWriter and manually export values and styles one by one by looping through the bound datasource.
I hope this will help.
Best Regards,
Noriko I.Developer Support Engineer,Infragistics, Inc.
Hi Noriko,
Thanks for the information.
To help us move a little faster with this, can I ask you to create a sample app outlining what needs to be done?
You don't need to do the whole lot, we are just interested to see what APIs we need to look at for borders and font weights.
I created a simple sample application.
In the sample, there are Styles targetting TreeCellValuePresenter and CellValuePresenter. Both styles have setters for BorderThickness and BorderBrush. BorderThickness Value is bound to a converter which gets DataItem's IsLastOfGroup and returns Thickness(0, 1, 0, 0) if it is true and returns Thickness(0, 0, 0, 0) otherwise. BorderBrush Value is bound to a converter which gets DataItem's IsLastOfGroup and returns Colors.Black if it is true and returns nothing otherwise. Those styles are to simulate what you do about BorderThickness and BorderBrush in your sample application.
Exporting to Excel is invoked when you click the button "Export to Excel". Most of what the sample does is similar to what you do in your sample application, except that it adds an event handler for CellExported of DataPresenterExcelExporter. In the event handler, if the cell's record is DataRecord and its DataItem's IsLastOfGroup is true, the top border of the exported cell is specified as Thick. And if its DataItem's IsLastOfGroup is false, the top border of the exported cell is specified as None.
Exporting to Word is invoked when you click the button "Export to Word". In the button click event, WordDocumentWriter is created and all of the exporting process is manually done through the instance. First, a table row is created as header and all the fields of the XamTreeGrid is exported as table cell. Then, looping through all the DataRecords of XamTreeGrid, the sample create a table row and export values as table cell. During this process, if DataItem's IsLastOfGroup is true, the cell's top border is styled as Single.
I hope this will help.WpfApp1.zip