I have a XamGrid with a number of UnboundColumn columns, each with a value converter. The correct values are being displayed on screen.
When I use XamGridExcelExporter to export to an excel file, the value converter is not called, and the "ToString" function of the row is exported in each cell.
Here is a cut-down version of the code I am using to build up the grid and export to excel.
<ig:XamGrid x:Name="SortableGrid" Grid.Row="1" AutoGenerateColumns="False" CellStyle="{StaticResource SummaryCellStyle}" ItemsSource="{Binding Rows}" > <ig:XamGrid.SortingSettings> <ig:SortingSettings AllowSorting="True"/> </ig:XamGrid.SortingSettings> <ig:XamGrid.FilteringSettings> <ig:FilteringSettings AllowFiltering="FilterMenu"/> </ig:XamGrid.FilteringSettings> <ig:XamGrid.ConditionalFormattingSettings> <ig:ConditionalFormattingSettings AllowConditionalFormatting="True"/> </ig:XamGrid.ConditionalFormattingSettings> <ig:XamGrid.Columns > <ig:UnboundColumn Tag="Display something while we wait for data to load" Key="StudentName" x:Uid="StudentNameColumn" IsFixed="Left" HeaderText="~Student"/> </ig:XamGrid.Columns>
</ig:XamGrid>
public void BuildHeaders() { int index = 0; SortableGrid.Columns.Clear(); foreach (var resultHeader in ViewModel.Results.Headers) { var column = new UnboundColumn { Key = resultHeader.Id ?? index.ToString(), HeaderText = resultHeader.Display, ValueConverter = new SelectResultCell(index), MinimumWidth = 150, }; if (index == 0) column.IsFixed = FixedState.Left; index++;
SortableGrid.Columns.Add(column); } SortableGrid.GroupBySettings = new GroupBySettings { AllowGroupByArea = GroupByAreaLocation.Top }; }
private async void OnExportExcelClick(object sender, RoutedEventArgs e) { var workbook = new Workbook(); workbook.SetCurrentFormat(WorkbookFormat.Excel2007);
var exporter = new XamGridExcelExporter { ExcludeColumnValueConverter = false }; exporter.Export(SortableGrid, workbook);
var savePicker = new FileSavePicker(); savePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
savePicker.FileTypeChoices.Add("Excel Workbook", new List<string>() { ".xlsx" }); savePicker.DefaultFileExtension = ".xlsx";
savePicker.SuggestedFileName = "Workbook1"; var file = await savePicker.PickSaveFileAsync(); if (file == null) return;
using (var stream = await file.OpenStreamForWriteAsync()) { workbook.Save(stream); }
Launcher.LaunchFileAsync(file); }
Hello Brian and thank you for posting!
I have used your code in order to create a sample application where the issue is reproducible and it seems that on my side the converter is working as expected and the correct value is displayed in the Excel document after the exporting. Could you please try run the attached sample and let me know if the issue is reproducible on your side? Would modify the sample or share another one where the converter is not working properly so I could investigate the behavior further. Thank you.
Thanks for creating the demo. It didn't run on my machine (Odd exception about not finding the Windows runtime). Very odd. I created a project from scratch and copied the code and I was able to export to Excel using the converter.
BUT...
I have located the problem and it is to do with the IValueConverter. I incorrectly had a constructor parameter in my converter. While this worked for the XamGrid, a new instance of the converter was created for the excel export.
I changed my code to use the ValueConverterParameter property in the UnboundColumn and changed the converter. Again, this worked just find for the XamGrid, and the export to Excel created a new instance of the converter. I expected the exporter to pass the same ValueConverterParameter, but it did not. Attached is the modified project with the export error.
Hello,
Thank you for the provided sample. I have logged this behavior in our tracking system with ID 174686 and the following case was created for you: CAS-139696-X4M8X6. The next step will be for a developer to review my investigation and confirm my findings or to offer a fix, or other resolution.
We have shipped out a new service release where your issue is resolved. I'd be glad to find out if you had tested it out and if it had met your requirements.You can download the Service Releases by logging to our web site and going to Account\My Keys and Downloads.