Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
85
XamGridExcelExporter does not call value converter
posted

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);
}