Create an Excel file in MAUI

GemBox.Spreadsheet is a standalone .NET component with cross-platform support for processing spreadsheets. With the help of MAUI, you can use it on platforms like Android, iOS, Linux, and macOS for reading, writing, editing, and converting Excel files.

The following example shows how you can create a XLSX file in a mobile application.

Excel file generator on a native Android mobile app with MAUI
Screenshot of MAUI Android app that creates an Excel file
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="SpreadsheetMaui.MainPage">

    <ScrollView>
        <VerticalStackLayout
            Spacing="20"
            Padding="50"
            VerticalOptions="Center">

            <Label
               Text="GemBox.Spreadsheet Example"
               HorizontalOptions="Center"
               FontSize="Large"
               Margin="0,0,0,30" />

            <TableView x:Name="table" Intent="Data" >
                <TableRoot>
                    <TableSection>
                        <EntryCell Label="A1" Text="Joe Doe" />
                        <EntryCell Label="A2" Text="Fred Nurk" />
                        <EntryCell Label="A3" Text="Hans Meier" />
                        <EntryCell Label="A4" Text="Ivan Horvat" />
                        <EntryCell Label="A5" Text="Jean Dupont" />
                    </TableSection>
                </TableRoot>
            </TableView>

            <ActivityIndicator x:Name="activity" />

            <Button
                x:Name="button"
                Text="Create workbook"
                Clicked="Button_Clicked"/>

        </VerticalStackLayout>
    </ScrollView>

</ContentPage>
using GemBox.Spreadsheet;
using System;
using System.IO;
using System.Threading.Tasks;

namespace SpreadsheetMaui
{
    public partial class MainPage : ContentPage
    {
        static MainPage()
        {
            SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");
        }

        public MainPage()
        {
            InitializeComponent();
        }

        private async Task<string> CreateWorkbookAsync()
        {
            var workbook = new ExcelFile();
            var worksheet = workbook.Worksheets.Add("Sheet1");

            foreach (var cell in table.Root[0].Cast<EntryCell>())
                worksheet.Cells[cell.Label].Value = cell.Text;

            worksheet.Columns["A"].AutoFit();

            using var stream = new MemoryStream();
            using (var imageStream = await FileSystem.OpenAppPackageFileAsync("dices.png"))
                await imageStream.CopyToAsync(stream);
            worksheet.Pictures.Add(stream, ExcelPictureFormat.Png, "C1", "E5");

            var filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Example.pdf");

            await Task.Run(() => workbook.Save(filePath));

            return filePath;
        }

        private async void Button_Clicked(object sender, EventArgs e)
        {
            button.IsEnabled = false;
            activity.IsRunning = true;

            try
            {
                var filePath = await CreateWorkbookAsync();
                await Launcher.OpenAsync(new OpenFileRequest(Path.GetFileName(filePath), new ReadOnlyFile(filePath)));
            }
            catch (Exception ex)
            {
                await DisplayAlert("Error", ex.Message, "Close");
            }

            activity.IsRunning = false;
            button.IsEnabled = true;
        }
    }
}

Limitations on Android or iOS

You can use the full functionality of GemBox.Spreadsheet in MAUI applications, but with the following exceptions:

These features currently depend on WPF and require a .NET Windows Desktop Runtime. However, we plan to add cross-platform support for them in future releases.

See also


Next steps

GemBox.Spreadsheet is a .NET component that enables you to read, write, edit, convert, and print spreadsheet files from your .NET applications using one simple API.

Download Buy