Skip to content

Commit 1f7071e

Browse files
committed
excel pub.dev
0 parents  commit 1f7071e

12 files changed

+1868
-0
lines changed

.gitignore

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.DS_Store?
8+
.atom/
9+
.buildlog/
10+
.history
11+
.svn/
12+
13+
# IntelliJ related
14+
*.iml
15+
*.ipr
16+
*.iws
17+
.idea/
18+
19+
# The .vscode folder contains launch configuration and tasks you configure in
20+
# VS Code which you may wish to be included in version control, so this line
21+
# is commented out by default.
22+
.vscode/
23+
24+
# Flutter/Dart/Pub related
25+
**/doc/api/
26+
.dart_tool/
27+
.flutter-plugins
28+
.flutter-plugins-dependencies
29+
.packages
30+
.pub-cache/
31+
.pub/
32+
build/
33+
34+
# Android related
35+
**/android/**/gradle-wrapper.jar
36+
**/android/.gradle
37+
**/android/captures/
38+
**/android/gradlew
39+
**/android/gradlew.bat
40+
**/android/local.properties
41+
**/android/**/GeneratedPluginRegistrant.java
42+
43+
# iOS/XCode related
44+
**/ios/**/*.mode1v3
45+
**/ios/**/*.mode2v3
46+
**/ios/**/*.moved-aside
47+
**/ios/**/*.pbxuser
48+
**/ios/**/*.perspectivev3
49+
**/ios/**/*sync/
50+
**/ios/**/.sconsign.dblite
51+
**/ios/**/.tags*
52+
**/ios/**/.vagrant/
53+
**/ios/**/DerivedData/
54+
**/ios/**/Icon?
55+
**/ios/**/Pods/
56+
**/ios/**/.symlinks/
57+
**/ios/**/profile
58+
**/ios/**/xcuserdata
59+
**/ios/.generated/
60+
**/ios/Flutter/App.framework
61+
**/ios/Flutter/Flutter.framework
62+
**/ios/Flutter/Flutter.podspec
63+
**/ios/Flutter/Generated.xcconfig
64+
**/ios/Flutter/app.flx
65+
**/ios/Flutter/app.zip
66+
**/ios/Flutter/flutter_assets/
67+
**/ios/Flutter/flutter_export_environment.sh
68+
**/ios/ServiceDefinitions.json
69+
**/ios/Runner/GeneratedPluginRegistrant.*
70+
71+
# Exceptions to above rules.
72+
!**/ios/**/default.mode1v3
73+
!**/ios/**/default.mode2v3
74+
!**/ios/**/default.pbxuser
75+
!**/ios/**/default.perspectivev3
76+
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages

.metadata

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This file tracks properties of this Flutter project.
2+
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3+
#
4+
# This file should be version controlled and should not be manually edited.
5+
6+
version:
7+
revision: 0b8abb4724aa590dd0f429683339b1e045a1594d
8+
channel: stable
9+
10+
project_type: package

CHANGELOG.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Changelog
2+
All notable changes to this project will be documented in this file.
3+
4+
## [Future Updates coming soon]
5+
- Spanning of Rows and Columns
6+
7+
## [1.0.0] - 2020-02-18
8+
### Added
9+
- TextWrapping and (Clip in Google Sheets) / (ShrinkToFit in Microsoft Excel)
10+
- Horizontal and Vertical Alignment
11+
- Update Cell by Cell-Name ("A1")
12+
- Minor Bug Fixes

LICENSE

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
3+
Copyright (C) 2020 - Kawaljeet Singh
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Excel
2+
3+
Excel is a flutter and dart library for creating and updating excel-sheets for XLSX files.
4+
5+
## Usage
6+
7+
### In Flutter App
8+
9+
import 'dart:io';
10+
import 'package:path/path.dart';
11+
import 'package:excel/excel.dart';
12+
13+
...
14+
15+
var decoder = Excel.createExcel();
16+
17+
/**
18+
* Create new Excel Sheet
19+
* var decoder = Excel.createExcel();
20+
*
21+
* ------------ Or ------------
22+
* For Editing Pre-Existing Excel File
23+
*
24+
* var file = "Path_to_pre_existing_Excel_File/NewExcel.xlsx";
25+
* var bytes = File(file).readAsBytesSync();
26+
* var decoder = Excel.decodeBytes(bytes, update: true);
27+
**/
28+
29+
for (var table in decoder.tables.keys) {
30+
print(table);
31+
print(decoder.tables[table].maxCols);
32+
print(decoder.tables[table].maxRows);
33+
for (var row in decoder.tables[table].rows) {
34+
print("$row");
35+
}
36+
}
37+
38+
/**
39+
* Define Your own sheet name
40+
* var sheet = 'SheetName'
41+
*
42+
* ---------- Or ----------
43+
* Find the desired sheet by iterating throught the [existing sheets]:
44+
* var sheet;
45+
* for (var tableName in decoder.tables.keys) {
46+
* if( desiredSheetName.toString() == tableName.toString() ){
47+
* sheet = tableName.toString();
48+
* break;
49+
* }
50+
* }
51+
*/
52+
53+
// if [MySheetName] does not exist then it will be automatically created.
54+
var sheet = 'MySheetName';
55+
56+
decoder
57+
..updateCell(sheet, CellIndex.indexByString("A1"), "A1",
58+
fontColorHex: "#1AFF1A", verticalAlign: VerticalAlign.Top)
59+
..updateCell(
60+
sheet, CellIndex.indexByColumnRow(columnIndex: 2, rowIndex: 0), "C1",
61+
wrap: TextWrapping.WrapText)
62+
..updateCell(sheet, CellIndex.indexByString("A2"), "A2",
63+
backgroundColorHex: "#1AFF1A")
64+
..updateCell(sheet, CellIndex.indexByString("E5"), "E5",
65+
horizontalAlign: HorizontalAlign.Right);
66+
67+
// Save the file
68+
69+
decoder.encode().then((onValue) {
70+
File(join("/Users/kawal/Desktop/excel.xlsx"))
71+
..createSync(recursive: true)
72+
..writeAsBytesSync(onValue);
73+
});
74+
75+
...
76+
77+
## Features coming in next version
78+
On-going implementation for future:
79+
- spanned rows (Comming Soon in future updates)
80+
- spanned columns (Comming Soon in future updates)
81+
82+
## Important:
83+
For XLSX format, this implementation only supports native Excel format for date, time and boolean type conversion.
84+
In other words, custom format for date, time, boolean aren't supported and also the files exported from LibreOffice as well.
85+
86+
## Support on Beerpay
87+
Hey dude! Help me out for a couple of :beers:!

example/excel_example.dart

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import 'dart:io';
2+
import 'package:path/path.dart';
3+
import 'package:excel/excel.dart';
4+
5+
void main(List<String> args) {
6+
var file = "/Users/kawal/Desktop/excel.xlsx";
7+
var bytes = File(file).readAsBytesSync();
8+
var decoder = Excel.decodeBytes(bytes, update: true);
9+
10+
for (var table in decoder.tables.keys) {
11+
print(table);
12+
print(decoder.tables[table].maxCols);
13+
print(decoder.tables[table].maxRows);
14+
for (var row in decoder.tables[table].rows) {
15+
print("$row");
16+
}
17+
}
18+
19+
// if sheet with name = Sheet24 does not exist then it will be automatically created.
20+
var sheet = 'Sheet24';
21+
22+
decoder
23+
..updateCell(sheet, CellIndex.indexByString("A1"), "Here Value of A1",
24+
fontColorHex: "#1AFF1A", verticalAlign: VerticalAlign.Top)
25+
..updateCell(sheet, CellIndex.indexByColumnRow(columnIndex: 2, rowIndex: 0),
26+
"Here Value of C1", wrap: TextWrapping.WrapText)
27+
..updateCell(sheet, CellIndex.indexByString("A2"), "Here Value of A2",
28+
backgroundColorHex: "#1AFF1A")
29+
..updateCell(sheet, CellIndex.indexByString("E5"), "Here Value of E5",
30+
horizontalAlign: HorizontalAlign.Right);
31+
32+
decoder.encode().then((onValue) {
33+
File(join("/Users/kawal/Desktop/excel_out.xlsx"))
34+
..createSync(recursive: true)
35+
..writeAsBytesSync(onValue);
36+
}).then((_) {
37+
print(
38+
"\n****************************** Printing Updated Data Directly by reading output file ******************************\n");
39+
var fileOut = "/Users/kawal/Desktop/excel_out.xlsx";
40+
var bytesOut = File(fileOut).readAsBytesSync();
41+
var decoderOut = Excel.decodeBytes(bytesOut, update: true);
42+
43+
for (var table in decoderOut.tables.keys) {
44+
print(table);
45+
print(decoderOut.tables[table].maxCols);
46+
print(decoderOut.tables[table].maxRows);
47+
for (var row in decoderOut.tables[table].rows) {
48+
print("$row");
49+
}
50+
}
51+
});
52+
}

lib/excel.dart

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
library excel;
2+
3+
import 'dart:convert';
4+
import 'dart:typed_data';
5+
6+
import 'package:archive/archive.dart';
7+
import 'package:xml/xml.dart';
8+
9+
part 'src/excel.dart';
10+
part 'src/xlsx.dart';

0 commit comments

Comments
 (0)