justkawal / excel

Excel Library for Flutter and Dart - https://pub.dev/packages/excel
MIT License
427 stars 238 forks source link

[Feature] Convert to PDF #121

Open nambui2000k opened 3 years ago

nambui2000k commented 3 years ago

when will there be feature to convert excel to pdf

ya332 commented 3 years ago

Patiently waiting for an update.

devr-tech commented 2 years ago

Patiently waiting for an update too.

justkawal commented 2 years ago

I can implement this functionality but Waiting on this: https://github.com/DavBfr/dart_pdf/issues/313

ya332 commented 2 years ago

I have solved my issue by creating this method to convert from an array of data to PDF. I am posting here in case it might help. Cheers.

import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:pdf/widgets.dart' as pw;

exportAsPDF() async {
    // load data to list
    final allData = await getAllData();

    List<String> headers = ['DATE', 'SYS', 'DIA', 'PUL', 'TYPE', 'TAGS'];
    List<List<String>> bpDocument = [];

    allData.forEach((element) {
      bpDocument.add(<String>[
        element['dateTime'].toDate().toString(),
        element['systolic'].toString(),
        element['diastolic'].toString(),
        element['pulse'].toString(),
        element['type'].toString(),
        element['tags'].toString(),
      ]);
    });

    final pdf = pw.Document();
    pdf.addPage(pw.Page(
      build: (context) => pw.Table.fromTextArray(
        headers: headers,
        data: bpDocument,
      ),
    ));

    final bytes = await pdf.save();

    if (kIsWeb) {
      // running on the web!
      download(bytes,
          downloadName: DateFormat('yMMdd').format(DateTime.now()).toString() +
              "_export.pdf");
    } else {
      Directory appDocDir = await getApplicationDocumentsDirectory();
      String appDocPath = appDocDir.path;

      String filePath = appDocPath +
          "/" +
          DateFormat('yMMdd').format(DateTime.now()).toString() +
          "_export" +
          ".pdf";

      final File file = File(filePath);
      await file.writeAsBytes(bytes);

      //open share dialog
      Share.shareFiles([filePath]);

      return file;
    }
  }
justkawal commented 2 years ago

@ya332 That would work for sure, but not for span and merge case-scenario.

fcunnn commented 8 months ago

Looking forward to updates,I really need this feature