π Handle Excel Files Like a Pro in Flutter with the excel Package
FlutterPulseThis 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
.xlsxspreadsheets 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
.xlsxfiles 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!