I am using a SfDataGrid which DataSource is bound to an ObservableCollection.
For further information in terms of data evaluation I added a TableSummaryRow and serveral UnboundRows.
The complete SfDataGrid should be able to be exported to Excel and also to PDF.
As mentionend in Your Documentation UnboundRows are not exported by Default.
Therefor I edited the DataGridExcelExportingOption and DataGridPdfExportOption as following code snippets show:
Excel:
DataGridExcelExportingController excelExport = new DataGridExcelExportingController();
var excelEngine = excelExport.ExportToExcel(sfDataGrid, new DataGridExcelExportingOption()
{
ExportTableSummary = true,
ExportUnboundRows = true,
});
var workbook = excelEngine.Excel.Workbooks[0];
MemoryStream stream = new MemoryStream();
workbook.SaveAs(stream);
workbook.Close();
excelEngine.Dispose();
//Holen der plattformspezifischen Implementierung des Interfaces mittels DependecyService
DependencyService.Get<IFileOperator>().Save("DataGrid.xlsx", "application/msexcel", stream);
PDF:
DataGridPdfExportingController pdfExport = new DataGridPdfExportingController();
MemoryStream stream = new MemoryStream();
var exportToPdf = pdfExport.ExportToPdf(sfDataGrid, new DataGridPdfExportOption()
{
ExportTableSummary = true,
//ExportUnboundRows = true, //!!!"NullReference"!!!
FitAllColumnsInOnePage = true,
});
exportToPdf.Save(stream);
exportToPdf.Close(true);
//Holen der plattformspezifischen Implementierung des Interfaces mittels DependecyService
DependencyService.Get<IFileOperator>().Save("DataGrid.pdf", "application/pdf", stream);
While
the Excel-Export works perfectly fine (showing TableSummaryRow and
UnboundRow), the PDF-Export just is able to export the TableSummaryRow.
Trying to export the UnboundRow throws an exception:
| Name | Wert | Typ |
▶ | $exception | {System.NullReferenceException: Object reference not set to an instance of an object.
at Syncfusion.SfDataGrid.XForms.Exporting.DataGridPdfExportingController.ExportUnboundRowToPdf(SfDataGrid dataGrid, PdfGridRow pdfRow, DataGridPdfExportOption exportOption, GridUnboundRow gridUnboundRow, ExportCellType cellType)
at Syncfusion.SfDataGrid.XForms.Exporting.DataGridPdfExportingController.ExportUnboundRowsToPdf(SfDataGrid dataGrid, PdfGrid pdfGrid, DataGridPdfExportOption exportOption, UnboundRowsPosition position, Boolean belowSummary, ObservableCollection`1 unBoundRows)
at Syncfusion.SfDataGrid.XForms.Exporting.DataGridPdfExportingController.ExportToPdfGrid(SfDataGrid dataGrid, ICollectionViewAdv collectionView, DataGridPdfExportOption exportOption, PdfDocument pdfDocument)
at Syncfusion.SfDataGrid.XForms.Exporting.DataGridPdfExportingController.ExportToPdf(SfDataGrid dataGrid, ICollectionViewAdv collectionView, DataGridPdfExportOption exportOption)
at Syncfusion.SfDataGrid.XForms.Exporting.DataGridPdfExportingController.ExportToPdf(SfDataGrid dataGrid, DataGridPdfExportOption exportOption)
at XSyncfusionContentViews.ViewModels.XTableOperatorButtonsViewModel.ExportToPDF(SfDataGrid sfDataGrid)
at XSyncfusionContentViews.Views.XTableOperatorButtonsView.Pdf_Clicked(Object sender, EventArgs e)
at Xamarin.Forms.Button.Xamarin.Forms.Internals.IButtonElement.PropagateUpClicked()
at Xamarin.Forms.ButtonElement.ElementClicked(VisualElement visualElement, IButtonElement ButtonElementManager)
at Xamarin.Forms.Button.SendClicked()
at Xamarin.Forms.Platform.UWP.ButtonRenderer.OnButtonClick(Object sender, RoutedEventArgs e)} | System.NullReferenceException |
I am using the following versions of NuGet-Packages:
- Syncfusion.Xamarin.DataGridExport 16.4.0.54
- Syncfusion.Xamarin.Pdf 16.4.0.54
- Syncfusion.Xamarin.SfDataGrid 16.4.0.54
- Syncfusion.Xamarin.XlsIO 16.4.0.54
I would be glad, if You can help me find a solution for this particular problem. I am looking forward to hear from You soon.
Kind regards
Julian