excel 1.0.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 86

Excel #

Excel is a flutter and dart library for creating and updating excel-sheets for XLSX files.

Usage #

In Flutter App #

import 'dart:io';
import 'package:path/path.dart';
import 'package:excel/excel.dart';

...

var decoder = Excel.createExcel();

/**
 * Create new Excel Sheet
 * var decoder = Excel.createExcel();
 *  
 * ------------ Or ------------
 * For Editing Pre-Existing Excel File
 * 
 * var file = "Path_to_pre_existing_Excel_File/NewExcel.xlsx";
 * var bytes = File(file).readAsBytesSync();
 * var decoder = Excel.decodeBytes(bytes, update: true);
 **/
 
for (var table in decoder.tables.keys) {
  print(table);
  print(decoder.tables[table].maxCols);
  print(decoder.tables[table].maxRows);
  for (var row in decoder.tables[table].rows) {
    print("$row");
  }
}

/**
 * Define Your own sheet name
 * var sheet = 'SheetName'
 * 
 * ---------- Or ----------
 * Find the desired sheet by iterating throught the [existing sheets]:
 * var sheet;
 * for (var tableName in decoder.tables.keys) {
 *    if( desiredSheetName.toString() == tableName.toString() ){
 *      sheet = tableName.toString();
 *      break;
 *    }
 * }
 */

// if sheet with name = 'MySheetName' does not exist then it will be automatically created.
var sheet = 'MySheetName';

  decoder
..updateCell(sheet, CellIndex.indexByString("A1"), "Here value of A1",
    fontColorHex: "#1AFF1A", verticalAlign: VerticalAlign.Top)
..updateCell(
    sheet, CellIndex.indexByColumnRow(columnIndex: 2, rowIndex: 0), "Here value of C1",
    wrap: TextWrapping.WrapText)
..updateCell(sheet, CellIndex.indexByString("A2"), "Here value of A2",
    backgroundColorHex: "#1AFF1A")
..updateCell(sheet, CellIndex.indexByString("E5"), "Here value of E5",
    horizontalAlign: HorizontalAlign.Right);

// Save the file

decoder.encode().then((onValue) {
  File(join("Path_to_destination/excel.xlsx"))
    ..createSync(recursive: true)
    ..writeAsBytesSync(onValue);
});

...

Features coming in next version #

On-going implementation for future:

  • spanned rows (Comming Soon in future updates)
  • spanned columns (Comming Soon in future updates)

Important: #

For XLSX format, this implementation only supports native Excel format for date, time and boolean type conversion. In other words, custom format for date, time, boolean aren't supported and also the files exported from LibreOffice as well.

Changelog #

All notable changes to this project will be documented in this file.

[Future Updates coming soon] #

  • Spanning of Rows and Columns

[1.0.2] - 2020-02-18 #

Improved #

  • Minor Bugs

[1.0.1] - 2020-02-18 #

Improved #

  • Health Maintenance

[1.0.1] - 2020-02-18 #

Added #

  • TextWrapping and (Clip in Google Sheets) / (ShrinkToFit in Microsoft Excel)
  • Horizontal and Vertical Alignment
  • Update Cell by Cell-Name ("A1")
  • Minor Bug Fixes

example/excel_example.dart

import 'dart:io';
import 'package:path/path.dart';
import 'package:excel/excel.dart';

void main(List<String> args) {
  var file = "Path_to_input/excel.xlsx";
  var bytes = File(file).readAsBytesSync();
  var decoder = Excel.decodeBytes(bytes, update: true);

  for (var table in decoder.tables.keys) {
    print(table);
    print(decoder.tables[table].maxCols);
    print(decoder.tables[table].maxRows);
    for (var row in decoder.tables[table].rows) {
      print("$row");
    }
  }

  // if sheet with name = Sheet24 does not exist then it will be automatically created.
  var sheet = 'Sheet24';

  decoder
    ..updateCell(sheet, CellIndex.indexByString("A1"), "Here Value of A1",
        fontColorHex: "#1AFF1A", verticalAlign: VerticalAlign.Top)
    ..updateCell(sheet, CellIndex.indexByColumnRow(columnIndex: 2, rowIndex: 0),
        "Here Value of C1", wrap: TextWrapping.WrapText)
    ..updateCell(sheet, CellIndex.indexByString("A2"), "Here Value of A2",
        backgroundColorHex: "#1AFF1A")
    ..updateCell(sheet, CellIndex.indexByString("E5"), "Here Value of E5",
        horizontalAlign: HorizontalAlign.Right);

  decoder.encode().then((onValue) {
    File(join("Path_to_destination/excel_out.xlsx"))
      ..createSync(recursive: true)
      ..writeAsBytesSync(onValue);
  }).then((_) {
    print(
        "\n****************************** Printing Updated Data Directly by reading output file ******************************\n");
    var fileOut = "Path_to_destination/excel_out.xlsx";
    var bytesOut = File(fileOut).readAsBytesSync();
    var decoderOut = Excel.decodeBytes(bytesOut, update: true);

    for (var table in decoderOut.tables.keys) {
      print(table);
      print(decoderOut.tables[table].maxCols);
      print(decoderOut.tables[table].maxRows);
      for (var row in decoderOut.tables[table].rows) {
        print("$row");
      }
    }
  });
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  excel: ^1.0.2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:excel/excel.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
76
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
86
Learn more about scoring.

We analyzed this package on Mar 30, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6

Health suggestions

Format lib/src/excel.dart.

Run dartfmt to format lib/src/excel.dart.

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (xml).

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
archive ^2.0.0 2.0.13
xml ^3.0.0 3.7.0 4.1.0
Transitive dependencies
args 1.6.0
charcode 1.1.3
collection 1.14.12
convert 2.1.1
crypto 2.1.4
meta 1.1.8
petitparser 3.0.2
typed_data 1.1.6
Dev dependencies
path ^1.5.1 1.6.4
test ^1.2.0