syncfusion_flutter_datagrid_export 20.4.43-beta copy "syncfusion_flutter_datagrid_export: ^20.4.43-beta" to clipboard
syncfusion_flutter_datagrid_export: ^20.4.43-beta copied to clipboard

The Syncfusion Flutter DataGrid Export library is used to export the DataGrid content to Excel and Pdf format with several customization options.

Flutter DataGrid Export Library #

Syncfusion's Flutter DataGrid export library is used to export the Flutter DataGrid to Excel and PDF formats. It provides support to export DataGrid content, such as headers, rows, stacked header rows, and table summary rows, with the several customization options.

Disclaimer: This is a commercial package. To use this package, you need to have either a Syncfusion commercial license or a free Syncfusion Community License. For more details, please check the LICENSE file.

Table of contents #

Get the demo application #

Explore the full capabilities of our Flutter widgets on your device by installing our sample browser applications from the following app stores, and view sample code in GitHub.

Check out the following resources to learn more about the Syncfusion Flutter DataGrid.

Installation #

Install the latest version from pub.

Getting started #

Import the following package.

import 'package:syncfusion_flutter_datagrid_export/export.dart';

Add the DataGrid to the application #

Follow the steps provided in this link to add the DataGrid to your application.

To export, add two buttons in the Row widget. Then, add the DataGrid in the Expanded widget and wrap both the buttons and DataGrid inside the Column widget.

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text(
          'Syncfusion Flutter DataGrid Export',
          overflow: TextOverflow.ellipsis,
        ),
      ),
      body: Column(
        children: <Widget>[
          Container(
            margin: const EdgeInsets.all(12.0),
            child: Row(
              children: <Widget>[
                SizedBox(
                  height: 40.0,
                  width: 150.0,
                  child: MaterialButton(
                      color: Colors.blue,
                      child: const Center(
                          child: Text(
                        'Export to Excel',
                        style: TextStyle(color: Colors.white),
                      )),
                      onPressed: exportDataGridToExcel),
                ),
                const Padding(padding: EdgeInsets.all(20)),
                SizedBox(
                  height: 40.0,
                  width: 150.0,
                  child: MaterialButton(
                      color: Colors.blue,
                      child: const Center(
                          child: Text(
                        'Export to PDF',
                        style: TextStyle(color: Colors.white),
                      )),
                      onPressed: exportDataGridToPdf),
                ),
              ],
            ),
          ),
          Expanded(
            child: SfDataGrid(
              source: employeeDataSource,
              columns: <GridColumn>[
                GridColumn(
                    columnName: 'ID',
                    label: Container(
                        padding: const EdgeInsets.all(16.0),
                        alignment: Alignment.center,
                        child: const Text(
                          'ID',
                        ))),
                GridColumn(
                    columnName: 'Name',
                    label: Container(
                        padding: const EdgeInsets.all(8.0),
                        alignment: Alignment.center,
                        child: const Text('Name'))),
                GridColumn(
                    columnName: 'Designation',
                    label: Container(
                        padding: const EdgeInsets.all(8.0),
                        alignment: Alignment.center,
                        child: const Text(
                          'Designation',
                          overflow: TextOverflow.ellipsis,
                        ))),
                GridColumn(
                    columnName: 'Salary',
                    label: Container(
                        padding: const EdgeInsets.all(8.0),
                        alignment: Alignment.center,
                        child: const Text('Salary'))),
              ],
            ),
          ),
        ],
      ),
    );
  }

Add GlobalKey for the DataGrid #

After adding the DataGrid, create the GlobalKey with the SfDataGridState class. Exporting related methods is available via the SfDataGridState class.

Set the created GlobalKey to the DataGrid.

final GlobalKey<SfDataGridState> _key = GlobalKey<SfDataGridState>();

...
    child: SfDataGrid(
    key: _key,
...

Export the DataGrid to Excel #

Use the exportToExcelWorkbook method from _key.currentState! and call this method in a button click.

  Future<void> exportDataGridToExcel() async {
    final Workbook workbook = _key.currentState!.exportToExcelWorkbook();
    final List<int> bytes = workbook.saveAsStream();
    File('DataGrid.xlsx').writeAsBytes(bytes);
    workbook.dispose();
  }

Export the DataGrid to PDF #

Use the exportToPdfDocument method from _key.currentState! and call this method in a button click.

  Future<void> exportDataGridToPdf() async {
    final PdfDocument document =
        _key.currentState!.exportToPdfDocument();

    final List<int> bytes = document.save();
    File('DataGrid.pdf').writeAsBytes(bytes);
    document.dispose();
  }

Support and feedback #

About Syncfusion #

Founded in 2001 and headquartered in Research Triangle Park, N.C., Syncfusion has more than 22,000 customers and more than 1 million users, including large financial institutions, Fortune 500 companies, and global IT consultancies.

Today, we provide 1,600+ controls and frameworks for web (ASP.NET Core, ASP.NET MVC, ASP.NET WebForms, JavaScript, Angular, React, Vue, Flutter, and Blazor) , mobile (.NET MAUI, Xamarin, Flutter, UWP, and JavaScript), and desktop development (.NET MAUI, Flutter, WinForms, WPF, UWP, and WinUI). We provide ready-to- deploy enterprise software for dashboards, reports, data integration, and big data processing. Many customers have saved millions in licensing fees by deploying our software.

70
likes
0
points
10.9k
downloads

Publisher

verified publishersyncfusion.com

Weekly Downloads

The Syncfusion Flutter DataGrid Export library is used to export the DataGrid content to Excel and Pdf format with several customization options.

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

collection, flutter, syncfusion_flutter_datagrid, syncfusion_flutter_pdf, syncfusion_flutter_xlsio

More

Packages that depend on syncfusion_flutter_datagrid_export