facebooktwittermenuarrow-up

GemBox Support Forum

Saving an excel file in UWP using ExcelFile.Save

I am converting a command-line based tool I built (using Excel sheets via GemBox.Spreadsheet) to Xamarin / UWP and am trying to figure out the best way to save out my XLSX data given the storage protection inherent in a UWP app.

If I just try to use the ExcelFile.Save() method I get protected storage errors and I haven’t found a way to stream that data through Windows.Storage successfully.

Has anyone done this, or is there a guide or some samples using GemBox.Spreadsheet to take my formatted workbook and save it out of a UWP app?

Hi Kyle,

I’m not sure in which context you’re saving the file.
Nevertheless, here is a small sample that shows how to save an Excel file with GemBox.Spreadsheet in UWP app using FileSavePicker:

private async void Button_Click(object sender, RoutedEventArgs e)
{
    var workbook = new ExcelFile();
    var worksheet = workbook.Worksheets.Add("Sheet1");

    var cell = worksheet.Cells["A1"];
    cell.Value = "Hello World";

    var stream = new MemoryStream();
    workbook.Save(stream, SaveOptions.XlsxDefault);

    var picker = new FileSavePicker();
    picker.FileTypeChoices.Add("Excel file", new string[] { ".xlsx" });
    picker.SuggestedStartLocation = PickerLocationId.Desktop;
    picker.SuggestedFileName = "Example.xlsx";

    var storage = await picker.PickSaveFileAsync();
    await FileIO.WriteBytesAsync(storage, stream.ToArray());
}

I hope this helps.

Regards,
Mario