Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,41 @@
# how_to_export_cellgrid_to_pdf
This sample demonstrates how to export SfCellGrid to PDF.
# How to Export UWP CellGrid to PDF?

This sample demonstrates how to export [UWP CellGrid](https://help.syncfusion.com/uwp/cellgrid/overview) (SfCellGrid) to PDF.

`SfCellGrid` does not have built-in function to export the grid data to PDF. To export the data into excel, create a new `PDFGrid` and set the grid data to pdfGrid cells using `Value` property and save that modified pdfGrid in a `PdfDocument`.

``` csharp
//Create a new PDF document.
PdfDocument pdfDocument = new PdfDocument();
//Create the page
PdfPage pdfPage = pdfDocument.Pages.Add();
//Create the parent grid
PdfGrid parentPdfGrid = new PdfGrid();
parentPdfGrid.Columns.Add(grid.ColumnCount);

for (int i = 0; i < grid.RowCount; i++)
{
//Add the rows
PdfGridRow row1 = parentPdfGrid.Rows.Add();
row1.Height = 50;
for (int j = 0; j < grid.ColumnCount; j++)
{
var style = grid.Model[i, j];
PdfGridCell pdfGridCell = parentPdfGrid.Rows[i].Cells[j];
pdfGridCell.Value = style.CellValue;
var brush = (style.Background as SolidColorBrush);
//Export with style
if (brush != null)
pdfGridCell.Style.BackgroundBrush = new PdfSolidBrush(new PdfColor(System.Drawing.Color.FromArgb(brush.Color.A, brush.Color.R, brush.Color.G, brush.Color.B)));
}
}

//Draw the PdfGrid.
parentPdfGrid.Draw(pdfPage, PointF.Empty);
StorageFile storageFile;
StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
storageFile = await local.CreateFileAsync("Sample.pdf", CreationCollisionOption.ReplaceExisting);
//Save the document.
await pdfDocument.SaveAsync(storageFile);
Windows.System.Launcher.LaunchFileAsync(storageFile);
```