Skip to content

SyncfusionExamples/how-to-export-cellgrid-to-excel

Repository files navigation

How to Export UWP CellGrid to Excel?

This example demonstrates how to export UWP CellGrid (SfCellGrid) to Microsoft Excel.

SfCellGrid does not have built-in function to export the grid data to excel. To export the data into excel, create a new excel file using the ExcelEngine and set the grid data to worksheet cells using IRange.Value property and save that modified workbook.

//Convert to excel
ExcelEngine excelEngine = new ExcelEngine();
excelEngine.Excel.DefaultVersion = ExcelVersion.Excel2016;
IApplication application = excelEngine.Excel;
 
IWorkbook workbook = application.Workbooks.Create(1);
 
IWorksheet sheet = workbook.Worksheets[0];
 
for (int i = 0; i < grid.RowCount; i++)
{
    for (int j = 0; j < grid.ColumnCount; j++)
    {
        IRange range = sheet[i + 1, j + 1];
        var style = grid.Model[i, j];
        var brush = (style.Background as SolidColorBrush);
        //Export with style
        if (brush != null)
            range.CellStyle.Color = brush.Color;
        range.Value = style.CellValue.ToString();
    }
}
StorageFile storageFile;
StorageFolder local = ApplicationData.Current.LocalFolder;
storageFile = await local.CreateFileAsync("Sample.xlsx", CreationCollisionOption.ReplaceExisting);
await workbook.SaveAsAsync(storageFile);
Windows.System.Launcher.LaunchFileAsync(storageFile);

About

This example demonstrates how to export SfCellGrid to Microsoft Excel

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 5

Languages