excel 1.0.2 copy "excel: ^1.0.2" to clipboard
excel: ^1.0.2 copied to clipboard

outdated

A flutter and dart library for creating, editing and updating excel sheets with compatible both on client and server side.

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");
      }
    }
  });
}
967
likes
0
pub points
99%
popularity

Publisher

verified publisherjustkawal.dev

A flutter and dart library for creating, editing and updating excel sheets with compatible both on client and server side.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

archive, xml

More

Packages that depend on excel