flutter_excel은 excel에서 파생된 Flutter 및 Dart 라이브러리로, 클라이언트 및 서버 환경에서 Excel 시트를 읽고, 생성하고, 편집하며 업데이트할 수 있게 해줍니다. Android, iOS, Web, macOS, Windows, Linux 등 여러 플랫폼을 지원하여 스프레드시트 기능이 필요한 크로스플랫폼 애플리케이션에 적합합니다. 외부 서비스에 의존하지 않고 Excel 파일을 처리할 수 있는 강력한 도구를 제공하여 데이터 프라이버시와 오프라인 사용 가능성을 보장합니다. 특히 Excel 형식으로 데이터 내보내기, 가져오기 또는 조작이 필요한 앱에 매우 유용합니다.
사용 사례
앱 데이터를 Excel로 내보내기
사용자가 업로드한 Excel 파일 가져오기
보고서 생성
재고 데이터 관리
템플릿 만들기
재무 기록 관리
주요 기능
크로스 플랫폼 지원
Excel 파일 읽기, 쓰기 및 편집
서버 및 클라이언트 호환성
외부 종속성 없음
다양한 파일 형식을 지원합니다
Flutter와의 간편한 통합
적합한 대상
데이터 기반 애플리케이션
보고 도구
재고 관리 시스템
재무 소프트웨어
교육 앱
데스크톱 및 모바일 앱
고려 사항
대용량 파일 처리는 성능에 영향을 미칠 수 있습니다
제한된 고급 형식 옵션
대규모 데이터 세트에 대한 주의 깊은 메모리 관리가 필요합니다
실시간 공동 편집에 적합하지 않습니다
하위 엑셀 라이브러리의 안정성에 의존
사용자 입력에 대한 추가 검증이 필요할 수 있습니다
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
Excel
Excel is a flutter and dart library for reading, creating and updating excel-sheets for XLSX files.
This library is MIT licensed So, it's free to use anytime, anywhere without any consent, because we believe in Open Source work.
Lets Get Started
1. Depend on it
Add this to your package's pubspec.yaml file:
dependencies:excel:any
2. Install it
You can install packages from the command line:
with pub:
$ pub get
with Flutter:
$ flutter packages get
3. Import it
Now in your Dart code, you can use:
import'package:excel/excel.dart';
Usage
Breaking Changes for those moving from 1.0.8 and below ----> 1.0.9 and above versions
The necessary changes to be made to updateCell function in order to prevent the code from breaking.
excel.updateCell('SheetName', CellIndex.indexByString("A2"), "Here value", backgroundColorHex: "#1AFF1A", horizontalAlign: HorizontalAlign.Right);
// Now in the above code wrap the optional arguments with CellStyle() and pass it to optional cellStyle parameter.// So the resulting code will look like
excel.updateCell('SheetName', CellIndex.indexByString("A2"), "Here value", cellStyle: CellStyle( backgroundColorHex: "#1AFF1A", horizontalAlign: HorizontalAlign.Right ) );
Protect helps you to apply and remove password protection on your excel file.
Read XLSX File
var file = "Path_to_pre_existing_Excel_File/excel_file.xlsx";
var bytes = File(file).readAsBytesSync();
var excel = Excel.decodeBytes(bytes);
for (var table in excel.tables.keys) {
print(table); //sheet Nameprint(excel.tables[table].maxCols);
print(excel.tables[table].maxRows);
for (var row in excel.tables[table].rows) {
print("$row");
}
}
Is your excel file password protected ? ( We got u covered )
Protect helps you to apply and remove password protection on your excel file.protect
Read XLSX in Flutter Web
Use FilePicker to pick files in Flutter Web. FilePicker
/// Use FilePicker to pick files in Flutter WebFilePickerResult pickedFile = awaitFilePicker.platform.pickFiles(
type: FileType.custom,
allowedExtensions: ['xlsx'],
allowMultiple: false,
);
/// file might be pickedif (pickedFile != null) {
var bytes = pickedFile.files.single.bytes;
var excel = Excel.decodeBytes(bytes);
for (var table in excel.tables.keys) {
print(table); //sheet Nameprint(excel.tables[table].maxCols);
print(excel.tables[table].maxRows);
for (var row in excel.tables[table].rows) {
print("$row");
}
}
}
Read XLSX from Flutter's Asset Folder
import'package:flutter/services.dart'showByteData, rootBundle;
/* Your blah blah code here */ByteData data = await rootBundle.load("assets/existing_excel_file.xlsx");
var bytes = data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
var excel = Excel.decodeBytes(bytes);
for (var table in excel.tables.keys) {
print(table); //sheet Nameprint(excel.tables[table].maxCols);
print(excel.tables[table].maxRows);
for (var row in excel.tables[table].rows) {
print("$row");
}
}
/*
* sheetObject.updateCell(cell, value, { CellStyle (Optional)});
* sheetObject created by calling - // Sheet sheetObject = excel['SheetName'];
* cell can be identified with Cell Address or by 2D array having row and column Index;
* Cell Style options are optional
*/Sheet sheetObject = excel['SheetName'];
CellStyle cellStyle = CellStyle(backgroundColorHex: "#1AFF1A", fontFamily : getFontFamily(FontFamily.Calibri));
cellStyle.underline = Underline.Single; // or Underline.Doublevar cell = sheetObject.cell(CellIndex.indexByString("A1"));
cell.value = 8; // dynamic values support provided;
cell.cellStyle = cellStyle;
// printing cell-typeprint("CellType: "+ cell.cellType.toString());
////// Inserting and removing column and rows// insert column at index = 8
sheetObject.insertColumn(8);
// remove column at index = 18
sheetObject.removeColumn(18);
// insert row at index = 82
sheetObject.insertRow(82);
// remove row at index = 80
sheetObject.removeRow(80);
Cell-Style Options
key
description
fontFamily
eg. getFontFamily(FontFamily.Arial) or getFontFamily(FontFamily.Comic_Sans_MS) There is total 182 Font Families available for now
fontSize
specify the font-size as integer eg. fontSize = 15
bold
makes text bold - when set to true, by-default it is set to false
italic
makes text italic - when set to true, by-default it is set to false
underline
Gives underline to text enum Underline { None, Single, Double } eg. Underline.Single, by-default it is set to Underline.None
fontColorHex
Font Color eg. "#0000FF"
rotation (degree)
rotation of text eg. 50, rotation varies from -90 to 90, with including 90 and -90
backgroundColorHex
Background color of cell eg. "#faf487"
wrap
Text wrapping enum TextWrapping { WrapText, Clip } eg. TextWrapping.Clip
verticalAlign
align text vertically enum VerticalAlign { Top, Center, Bottom } eg. VerticalAlign.Top
horizontalAlign
align text horizontally enum HorizontalAlign { Left, Center, Right } eg. HorizontalAlign.Right
Make sheet RTL
/*
* set rtl to true for making sheet to right-to-left
* default value of rtl = false ( which means the fresh or default sheet is ltr )
*
*/var sheetObject = excel['SheetName'];
sheetObject.rtl = true;
Copy sheet contents to another sheet
/*
* excel.copy(String 'existingSheetName', String 'anotherSheetName');
* existingSheetName should exist in excel.tables.keys in order to successfully copy
* if anotherSheetName does not exist then it will be automatically created.
*
*/
excel.copy('existingSheetName', 'anotherSheetName');
Rename sheet
/*
* excel.rename(String 'existingSheetName', String 'newSheetName');
* existingSheetName should exist in excel.tables.keys in order to successfully rename
*
*/
excel.rename('existingSheetName', 'newSheetName');
Delete sheet
/*
* excel.delete(String 'existingSheetName');
* (existingSheetName should exist in excel.tables.keys) and (excel.tables.keys.length >= 2), in order to successfully delete.
*
*/
excel.delete('existingSheetName');
Link sheet
/*
* excel.link(String 'sheetName', Sheet sheetObject);
*
* Any operations performed on (object of 'sheetName') or sheetObject then the operation is performed on both.
* if 'sheetName' does not exist then it will be automatically created and linked with the sheetObject's operation.
*
*/
excel.link('sheetName', sheetObject);
Un-Link sheet
/*
* excel.unLink(String 'sheetName');
* In order to successfully unLink the 'sheetName' then it must exist in excel.tables.keys
*
*/
excel.unLink('sheetName');
// After calling the above function be sure to re-make a new reference of this.Sheet unlinked_sheetObject = excel['sheetName'];
Merge Cells
/*
* sheetObject.merge(CellIndex starting_cell, CellIndex ending_cell, dynamic 'customValue');
* sheetObject created by calling - // Sheet sheetObject = excel['SheetName'];
* starting_cell and ending_cell can be identified with Cell Address or by 2D array having row and column Index;
* customValue is optional
*/
sheetObject.merge(CellIndex.indexByString("A1"), CellIndex.indexByString("E4"), customValue: "Put this text after merge");
Get Merged Cells List
// Check which cells are merged
sheetObject.spannedItems.forEach((cells) {
print("Merged:" + cells.toString());
});
Un-Merge Cells
/*
* sheetObject.unMerge(cell);
* sheetObject created by calling - // Sheet sheetObject = excel['SheetName'];
* cell should be identified with string only with an example as "A1:E4".
* to check if "A1:E4" is un-merged or not
* call the method excel.getMergedCells(sheet); and verify that it is not present in it.
*/
sheetObject.unMerge("A1:E4");
Find and Replace
/*
* int replacedCount = sheetObject.findAndReplace(source, target);
* sheetObject created by calling - // Sheet sheetObject = excel['SheetName'];
* source is the string or ( User's Custom Pattern Matching RegExp )
* target is the string which is put in cells in place of source
*
* it returns the number of replacements made
*/int replacedCount = sheetObject.findAndReplace(Flutter', 'Google');
Insert Row Iterables
/*
* sheetObject.insertRowIterables(list-iterables, rowIndex, iterable-options?);
* sheetObject created by calling - // Sheet sheetObject = excel['SheetName'];
* list-iterables === list of iterables which has to be put in specific row
* rowIndex === the row in which the iterables has to be put
* Iterable options are optional
*//// It will put the list-iterables in the 8th index rowList<String> dataList = ["Google", "loves", "Flutter", "and", "Flutter", "loves", "Excel"];
sheetObject.insertRowIterables(dataList, 8);
Iterable Options
key
description
startingColumn
starting column index from which list-iterables should be started
overwriteMergedCells
overwriteMergedCells is by-defalut set to true, when set to false it will stop over-write and will write only in unique cells
Append Row
/*
* sheetObject.appendRow(list-iterables);
* sheetObject created by calling - // Sheet sheetObject = excel['SheetName'];
* list-iterables === list of iterables
*/
sheetObject.appendRow(["Flutter", "till", "Eternity"]);
Get Default Opening Sheet
/*
* method which returns the name of the default sheet
* excel.getDefaultSheet();
*/var defaultSheet = excel.getDefaultSheet();
print("Default Sheet:" + defaultSheet.toString());
Set Default Opening Sheet
/*
* method which sets the name of the default sheet
* returns bool if successful then true else false
* excel.setDefaultSheet(sheet);
* sheet = 'SheetName'
*/var isSet = excel.setDefaultSheet(sheet);
if (isSet) {
print("$sheet is set to default sheet.");
} else {
print("Unable to set $sheet to default sheet.");
}
Saving
On Flutter Web
// when you are in flutter web then save() downloads the excel file.// Call function save() to download the filevar fileBytes = excel.save(fileName: "My_Excel_File_Name.xlsx");
On Android / iOS
For getting saving directory on Android or iOS, Use: path_provider
var fileBytes = excel.save();
var directory = awaitgetApplicationDocumentsDirectory();
File(join("$directory/output_file_name.xlsx"))
..createSync(recursive: true)
..writeAsBytesSync(fileBytes);
Frequent Issues
Having Trouble using excel i.e: every version of some_other_library depends on version..... blah blah blah
Similar issues have been solved in the past :#26, #25, #11