Working with Workbook

9 Apr 20211 minute to read

Saving a Excel workbook to file system

You can save the created or manipulated workbook to file system using SaveAsStream() 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.saveAsStream();
    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.saveAsStream();
    
    // Dipose the workbook.
    workbook.dispose();
    
    File('Output.xlsx').writeAsBytes(bytes);