πŸ“Š Handle Excel Files Like a Pro in Flutter with the excel Package

πŸ“Š Handle Excel Files Like a Pro in Flutter with the excel Package

FlutterPulse

This article was translated specially for the channel FlutterPulseYou'll find lots of interesting things related to Flutter on this channel. Don't hesitate to subscribe!πŸš€

Package: excel

Working with Excel files is a common need for many real-world apps β€” whether you're building a business dashboard, data analytics tool, school management system, or an inventory app.
The excel package in Flutter makes reading, creating, and modifying .xlsx files simple and efficient β€” without needing native dependencies.

πŸ” What is the excel Package?

The excel package is a pure Dart library that lets you read, write, and edit Excel spreadsheets directly in Flutter or Dart applications.
No external dependencies, no platform-specific plugins β€” just straightforward Excel manipulation that works everywhere.

With this package, you can:

  • πŸ“– Read Excel files directly from assets or file paths
  • 🧾 Create and export .xlsx spreadsheets dynamically
  • ✏️ Edit cells, add rows, and style data programmatically
  • πŸ’Ύ Save files locally or share them with users

βš™οΈ Installation

Add the package to your pubspec.yaml:

dependencies:
excel: ^4.0.3

Then run:

flutter pub get

πŸ§ͺ Usage Example

Here's how you can quickly create and save an Excel file:

import 'package:excel/excel.dart';
import 'dart:io';

void main() {
var excel = Excel.createExcel();
Sheet sheetObject = excel['Sheet1'];
// Add header row
sheetObject.appendRow(['ID', 'Name', 'Score']);
// Add data rows
sheetObject.appendRow([1, 'Alice', 85]);
sheetObject.appendRow([2, 'Bob', 92]);
sheetObject.appendRow([3, 'Charlie', 78]);
// Save file
var fileBytes = excel.save();
File('students.xlsx')
..createSync(recursive: true)
..writeAsBytesSync(fileBytes!);
}

βœ… This will generate an Excel file called students.xlsx with your data neatly arranged.

🧠 Reading Excel Files

You can also read existing Excel files easily:

import 'package:excel/excel.dart';
import 'dart:io';

void main() {
var bytes = File('students.xlsx').readAsBytesSync();
var excel = Excel.decodeBytes(bytes);
for (var table in excel.tables.keys) {
print(table); // Sheet name
print(excel.tables[table]!.rows);
}
}

This allows you to extract, display, or process data dynamically from Excel spreadsheets.

🌐 Platform Support

Since it's written purely in Dart:

  • Works on Flutter (Android, iOS, Web, Desktop)
  • Works in server-side Dart applications
  • No native code or dependencies needed

🧾 Real-World Use Cases

  • πŸ“ˆ Generate reports from app data
  • 🏫 Export student or employee records
  • πŸ›’ Create and manage inventory sheets
  • πŸ’Ό Integrate data export for analytics dashboards

⚠️ Things to Remember

  • Only .xlsx files are supported (not .xls)
  • Formatting support (like colors and fonts) is limited
  • For complex Excel operations, consider using APIs like Google Sheets or external Excel automation tools

🧾 Final Thoughts

The excel package is one of the most powerful data-handling tools in Flutter.
It helps you automate reporting, manage structured data, and build professional features β€” all within your Flutter app.

If your app deals with tabular data, this package can save you hours of manual work.
Simple, flexible, and fully Dart-native β€” that's what makes excel an essential package for Flutter developers.

If you found this story helpful, you can support me at Buy Me a Coffee!

Report Page