excel_to_json
एक फ्लटर पैकेज जो एक्सेल (.xlsx) फ़ाइलों को मल्टीपल वर्कशीट समर्थन और व्यापक त्रुटि हैंडलिंग के साथ JSON प्रारूप में बदलता है।
एक फ्लटर पैकेज जो एक्सेल (.xlsx) फ़ाइलों को JSON फॉर्मेट में बदलता है, आपके फ्लटर एप्लिकेशन में स्प्रेडशीट डेटा के साथ काम करना आसान बनाता है।
^4.0.3^10.2.1{"sdk":"flutter"}^6.0.0{"sdk":"flutter"}यह अंग्रेज़ी मूल स्नैपशॉट है। नवीनतम सामग्री GitHub पर देखें।
pub package License: MIT pub points popularity
A Flutter package that converts Excel (.xlsx) files to JSON format, making it easy to work with spreadsheet data in your Flutter applications.
import 'package:excel_to_json/excel_to_json.dart';
// Simple conversion
final converter = ExcelToJson();
final jsonString = await converter.convert(); // Opens file picker
// With custom configuration
final converter = ExcelToJson(
config: ExcelToJsonConfig(
includeEmptyRows: true,
verbose: true,
),
);
final result = await converter.convert();
✅ Simple Integration - Easy to use API with just a few lines of code
✅ Multiple Worksheets - Supports Excel files with multiple sheets
✅ Type Safety - Handles various cell types (text, numbers, dates, formulas, booleans)
✅ Configurable - Customizable conversion options
✅ Error Handling - Comprehensive error reporting and logging
✅ Cross Platform - Works on Android, iOS, Web, and Desktop
Add this to your package's pubspec.yaml file:
dependencies:
excel_to_json: ^1.5.0
Then run:
flutter pub get
import 'package:excel_to_json/excel_to_json.dart';
void convertExcelToJson() async {
final converter = ExcelToJson();
try {
final jsonString = await converter.convert();
if (jsonString != null) {
print('Conversion successful!');
print(jsonString);
} else {
print('No file selected or conversion cancelled.');
}
} on ExcelToJsonException catch (e) {
print('Conversion failed: ${e.message}');
}
}
import 'package:excel_to_json/excel_to_json.dart';
void convertWithConfig() async {
const config = ExcelToJsonConfig(
includeEmptyRows: true, // Include rows with all empty cells
useDateTimeStrings: false, // Keep date objects as native types
verbose: true, // Enable detailed logging
);
final converter = ExcelToJson(config: config);
try {
final jsonString = await converter.convert();
if (jsonString != null) {
// Process your JSON data
final data = jsonDecode(jsonString);
// Access worksheets by name
final sheet1Data = data['Sheet1'] as List<dynamic>;
for (final row in sheet1Data) {
print('Row data: $row');
}
}
} on ExcelToJsonException catch (e) {
print('Error: ${e.message}');
if (e.cause != null) {
print('Caused by: ${e.cause}');
}
}
}
The ExcelToJsonConfig class provides several options to customize the conversion:
| Option | Type | Default | Description |
|---|---|---|---|
includeEmptyRows |
bool |
false |
Include rows where all cells are empty |
useDateTimeStrings |
bool |
true |
Convert date/time values to strings |
dateFormat |
String? |
null |
Custom date format pattern (future feature) |
verbose |
bool |
false |
Enable detailed logging during conversion |
The package converts Excel files to JSON with the following structure:
{
"Sheet1": [
{
"Name": "John Doe",
"Age": 30,
"Email": "john@example.com"
},
{
"Name": "Jane Smith",
"Age": 25,
"Email": "jane@example.com"
}
],
"Sheet2": [
{
"Product": "Widget",
"Price": 19.99,
"InStock": true
}
]
}
Each worksheet becomes a top-level property, and each row (except the header) becomes an object in the array.
The package handles all standard Excel cell types:
null in JSONThe package provides detailed error information through the ExcelToJsonException class:
try {
final result = await converter.convert();
} on ExcelToJsonException catch (e) {
print('Conversion failed: ${e.message}');
// Check if there's an underlying cause
if (e.cause != null) {
print('Underlying error: ${e.cause}');
}
}
This package supports all platforms where Flutter runs:
.xlsx files (Excel 2007+ format).xls files (Excel 97-2003 format)Check out the /example folder for a complete Flutter app demonstrating how to use this package.
We welcome contributions! Please see our Contributing Guide for details.
git clone https://github.com/yourusername/excel_to_json.gitflutter pub getflutter testSee CHANGELOG.md for a detailed list of changes.
This project is licensed under the MIT License - see the LICENSE file for details.
If you find this package helpful, please give it a ⭐ on GitHub and pub.dev!