Skip to main content

daravel_excel 1.25.0 copy "daravel_excel: ^1.25.0" to clipboard
daravel_excel: ^1.25.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
160
points
561
downloads

Documentation

Documentation
API reference

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
Contributing

Topics

#excel #xlsx #csv #spreadsheet #server

Funding

Consider supporting this project:

github.com

License

MIT (license)

Dependencies

args, daravel, dartisan_cli, path, xml

More

Packages that depend on daravel_excel