Working with Workbook

14 Mar 20231 minute to read

Saving a Excel workbook to file system

You can save the created or manipulated workbook to file system using saveSync() method of Workbook. The workbook is saved in the XLSX format.

  • DART
  • // Creates a new instance for workbook.
    final Workbook workbook = Workbook();
    
    // Save the workbook in file system as XLSX format.
    final List<int> bytes = workbook.saveSync();
    workbook.dispose();
    
    File('Output.xlsx').writeAsBytes(bytes);

    Flutter XlsIO now supports saving an Excel document asynchronously using save() method of Workbook.

  • DART
  • // Creates a new instance for workbook.
    final Workbook workbook = Workbook();
    
    // Save the workbook in file system as XLSX format.
    final List<int> bytes = await workbook.save();
    workbook.dispose();
    
    File('Output.xlsx').writeAsBytes(bytes);

    Closing a workbook

    Once after the workbook manipulation and save operation are completed, you should dispose the instance of Workbook, in order to release all the memory consumed by XlsIO’s DOM. The following code snippet illustrates how dispose the instance of Workbook.

  • DART
  • // Creates a new instance for workbook.
    final Workbook workbook = new Workbook();
    
    // Save the workbook in file system as XLSX format.
    final List<int> bytes = workbook.saveSync();
    
    // Dipose the workbook.
    workbook.dispose();
    
    File('Output.xlsx').writeAsBytes(bytes);