PavelS0 / docx_template_dart

A Docx template engine
Apache License 2.0
40 stars 20 forks source link

How do I write the textform content into a docx file? #46

Closed batuhansavas-yilmaz closed 7 months ago

batuhansavas-yilmaz commented 8 months ago

I try using this function but it doesn't work


 Future<void> _saveFile() async {
    final data = await rootBundle.load('assets/template.docx');
    final bytes = data.buffer.asUint8List();
    final docx = await DocxTemplate.fromBytes(bytes);
    Content c = Content();

    c.add(TextContent("content", contentController.text));

    final d = await docx.generate(c);
    List<StorageInfo> storageInfo = await PathProviderEx2.getStorageInfo();
    var root = storageInfo[0].rootDir; // root of the "external storage"
    final directory = Directory("$root/Download");
    final file = File('${directory.path}/${nameController.text}.docx');
    if (d != null) await file.writeAsBytes(d);
  }
batuhansavas-yilmaz commented 7 months ago

I fixed.