-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Excel support & make it version 1.0.0 (#20)
* Add excel dependency * Upgrade some transitive dependencies * Start implementing file Excel format selection * Add a default choice for export path & document it * Use table in readme file * Fix empty cells bug in readme * Update Dart SDK version number to the latest stable * Prepare for exporting receiptProducts as xlsx * Add home_directory_helper & use it. Use path package (cross-platform) * Fine-tune printSelectedValues (fix indentations) * Add Excel exports for eanProducts & receiptProducts * Clean pubspec.yaml * Add cellStyle for receiptProducts xlsx * Add a minimum example & change version number (use 1.0.0) * Bold some texts in readme * Small update into replaceTildeWithHomeDirectory method * Some small K-ruoka specific fixes into runMainProgram * Add a todo message for K-ruoka EAN products * Add Excel stylizing for EAN products (& rename ean) * Refactoring (add SheetExtension for updating the row style) * Add green background color for some extra products * Update Dart SDK version & some transitive dependencies * Remove assets section from pubspec * A small update into the installation file * Update readme
- Loading branch information
Showing
21 changed files
with
351 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,23 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:path/path.dart' as p; | ||
|
||
import 'models/ean_product.dart'; | ||
import 'utils/date_helper.dart'; | ||
import 'utils/home_directory_helper.dart'; | ||
|
||
void eanProducts2CSV( | ||
List<EANProduct> eanProductList, String csvFilePath, String shopSelector) { | ||
void eanProducts2CSV(List<EANProduct> eanProductList, String exportFilePath, | ||
String shopSelector) { | ||
var csv = StringBuffer(); | ||
|
||
csv.write('Name;Quantity;Price per unit;Total price;EAN code;More details\n'); | ||
|
||
for (var item in eanProductList) { | ||
csv.write( | ||
'${item.name};${item.quantity};${item.pricePerUnit};${item.totalPrice};${item.ean};${item.moreDetails}\n'); | ||
'${item.name};${item.quantity};${item.pricePerUnit};${item.totalPrice};${item.eanCode};${item.moreDetails}\n'); | ||
} | ||
|
||
var file = File( | ||
'$csvFilePath/${shopSelector}_ean_products_${formattedDateTime()}.csv'); | ||
var file = File(p.join(replaceTildeWithHomeDirectory(exportFilePath), | ||
'${shopSelector}_ean_products_${formattedDateTime()}.csv')); | ||
file.writeAsString(csv.toString()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:excel/excel.dart'; | ||
import 'package:path/path.dart' as p; | ||
|
||
import 'models/ean_product.dart'; | ||
import 'utils/date_helper.dart'; | ||
import 'utils/home_directory_helper.dart'; | ||
import 'utils/extensions/sheet_extension.dart'; | ||
|
||
/// Saves EAN products as an Excel (xlsx) file. | ||
void eanProducts2Excel( | ||
List<EANProduct> products, String exportFilePath, String shopSelector) { | ||
var excel = Excel.createExcel(); | ||
var sheetObject = excel.sheets[excel.getDefaultSheet()]; | ||
|
||
// Write the header. | ||
var headerDataList = [ | ||
"Name", | ||
"Quantity", | ||
"Price per unit", | ||
"Total price", | ||
"EAN code", | ||
"More details" | ||
]; | ||
sheetObject?.insertRowIterables(headerDataList, 0); | ||
sheetObject?.updateSelectedRowStyle(0, CellStyle(bold: true)); | ||
|
||
// Write the products. | ||
for (var product in products) { | ||
var productDataList = [ | ||
product.name, | ||
product.quantity, | ||
product.pricePerUnit, | ||
product.totalPrice, | ||
product.eanCode, | ||
product.moreDetails | ||
]; | ||
sheetObject?.insertRowIterables( | ||
productDataList, products.indexOf(product) + 1); | ||
|
||
// If the product is a fruit or vegetable, change the background color to green. | ||
if (product.eanCode.startsWith("2") || product.eanCode.startsWith("02")) { | ||
sheetObject?.updateSelectedRowStyle(products.indexOf(product) + 1, | ||
CellStyle(backgroundColorHex: "#1AFF1A")); | ||
} | ||
// If the product is a packaging material, | ||
// change the font color to red and the background color to green. | ||
if (product.name == 'Pakkausmateriaalikustannukset') { | ||
sheetObject?.updateSelectedRowStyle(products.indexOf(product) + 1, | ||
CellStyle(fontColorHex: "#FF0000", backgroundColorHex: "#1AFF1A")); | ||
} | ||
|
||
// If the product is a home delivery, change the background color to green. | ||
if (product.name == 'Kotiinkuljetus') { | ||
sheetObject?.updateSelectedRowStyle(products.indexOf(product) + 1, | ||
CellStyle(backgroundColorHex: "#1AFF1A")); | ||
} | ||
} | ||
|
||
// Save to the Excel (xlsx) file: | ||
var fileBytes = excel.save(); | ||
|
||
File(p.join(replaceTildeWithHomeDirectory(exportFilePath), | ||
'${shopSelector}_ean_products_${formattedDateTime()}.xlsx')) | ||
..createSync(recursive: true) | ||
..writeAsBytesSync(fileBytes!); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.