Skip to main content

daravel_excel 1.15.0 copy "daravel_excel: ^1.15.0" to clipboard
daravel_excel: ^1.15.0 copied to clipboard

Excel and CSV exports and imports for Daravel, streamed with constant memory. Laravel Excel's concerns, validated imports with row numbers, downloads and disks.

example/main.dart

import 'package:daravel/daravel.dart';
import 'package:daravel_excel/daravel_excel.dart';

/// A report of the numbers 1 to 1 000 with their squares.
final class SquaresExport
    implements FromGenerator, WithHeadings, WithColumnFormatting {
  @override
  List<Object?> headings() => ['n', 'n²', 'Checked at'];

  @override
  Stream<Object?> generator() async* {
    for (var n = 1; n <= 1000; n++) {
      yield [n, n * n, DateTime.now()];
    }
  }

  @override
  Map<String, String> columnFormats() => {
    'B': NumberFormat.numberCommaSeparated1,
  };
}

/// Imports rows keyed by their headings and answers how many came.
final class CountImport with WithHeadingRow implements ToCollection {
  int count = 0;

  @override
  void collection(List<Map<String, Object?>> rows) => count = rows.length;
}

/// `GET /squares.xlsx` downloads the report; `POST /count` with a
/// `file` upload counts its rows.
Application createApp() => Application.configure(basePath: '.')
    .withRouting(
      api: (router) {
        router.get(
          '/squares.xlsx',
          (_) => Excel.download(SquaresExport(), 'squares.xlsx'),
        );
        router.post('/count', (Request request) async {
          final import = CountImport();
          await Excel.import(import, (await request.file('file'))!);
          return {'rows': import.count};
        });
      },
    )
    .create();

Future<void> main() async => Application.serveWith(createApp);
0
likes
0
points
1.13k
downloads

Documentation

Documentation

Publisher

verified publisherframework.daravel.dev

Weekly Downloads

Excel and CSV exports and imports for Daravel, streamed with constant memory. Laravel Excel's concerns, validated imports with row numbers, downloads and disks.

Homepage
Repository (GitHub)
View/report issues

Topics

#excel #xlsx #csv #spreadsheet #server

License

unknown (license)

Dependencies

args, daravel, dartisan_cli, path, xml

More

Packages that depend on daravel_excel