{"id":21639959,"url":"https://github.com/donnc/docxtpl","last_synced_at":"2025-04-11T16:52:44.185Z","repository":{"id":56828144,"uuid":"347654341","full_name":"DonnC/docxtpl","owner":"DonnC","description":" a word document .docx template plugin to easily populate and generate word documents from templates","archived":false,"fork":false,"pushed_at":"2024-08-04T11:02:49.000Z","size":2957,"stargazers_count":30,"open_issues_count":5,"forks_count":17,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-25T12:53:40.289Z","etag":null,"topics":["dart","docx","docx-template","flutter","flutter-plugin","word","word-document"],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/docxtpl","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DonnC.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"custom":["https://www.paypal.me/donnclab"]}},"created_at":"2021-03-14T14:08:53.000Z","updated_at":"2025-03-17T12:08:21.000Z","dependencies_parsed_at":"2023-02-15T06:45:58.991Z","dependency_job_id":null,"html_url":"https://github.com/DonnC/docxtpl","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DonnC%2Fdocxtpl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DonnC%2Fdocxtpl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DonnC%2Fdocxtpl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DonnC%2Fdocxtpl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DonnC","download_url":"https://codeload.github.com/DonnC/docxtpl/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248443383,"owners_count":21104402,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dart","docx","docx-template","flutter","flutter-plugin","word","word-document"],"created_at":"2024-11-25T04:15:48.401Z","updated_at":"2025-04-11T16:52:44.168Z","avatar_url":"https://github.com/DonnC.png","language":"Dart","funding_links":["https://www.paypal.me/donnclab"],"categories":[],"sub_categories":[],"readme":"# docxtpl\n\nA word document template plugin to easily populate and generate word documents from templates\n\n## screenshots\n\u003ctable\u003e\n   \u003ctr\u003e\n      \u003ctd\u003e Generate From Asset template .docx\u003c/td\u003e\n      \u003ctd\u003e Generate From Remote Template .docx\u003c/td\u003e\n      \u003ctd\u003e Generate From Local Template .docx\u003c/td\u003e\n   \u003c/tr\u003e\n   \u003ctr\u003e\n      \u003ctd\u003e\u003cimg src=\"https://raw.githubusercontent.com/DonnC/docxtpl/main/example/demo/docxtpl-asset.gif\"\u003e\u003c/td\u003e\n      \u003ctd\u003e\u003cimg src=\"https://raw.githubusercontent.com/DonnC/docxtpl/main/example/demo/docxtpl-remote.gif\"\u003e\u003c/td\u003e\n      \u003ctd\u003e\u003cimg src=\"https://raw.githubusercontent.com/DonnC/docxtpl/main/example/demo/docxtpl-local.gif\"\u003e\u003c/td\u003e\n   \u003c/tr\u003e\n\u003c/table\u003e\n\n\n## Installation\n- add `docxtpl` plugin to your `pubspec.yaml` file\n```yaml\ndependencies:\n  flutter:\n    sdk: flutter\n\n  docxtpl: \n```\n\n## Motive\n- I tried looking for plugins where i can work with word documents and i wasn't lucky to find what i really needed. From my `python` background i found helpful packages that work around `templating` and i thought maybe i can do something like that in `flutter`\n- The idea is to first make an example of the document you want to generate with microsoft word as you want. Then as you are creating your `.docx` word document, you insert `jinja2`-like tags like `{{my-tag-name}}` for example. If you want to put a `name` placeholder to populate later using this plugin, do it like `{{name}}` directly in the document.\n- You then save the word document as `.docx` (xml formart) and this is your .docx template file (tpl)\n- Now you can use `docxtpl` plugin to generate as many word documents as you want from this tpl file and the fields you will provide\n\n### Template file before and after using `docxtpl` plugin\n\u003ctable\u003e\n   \u003ctr\u003e\n      \u003ctd\u003e Before: word document template .docx\u003c/td\u003e\n      \u003ctd\u003e After(with docxtpl plugin): template .docx\u003c/td\u003e\n   \u003c/tr\u003e\n   \u003ctr\u003e\n      \u003ctd\u003e\u003cimg src=\"https://raw.githubusercontent.com/DonnC/docxtpl/main/example/demo/docxtpl-tpl.png\"\u003e\u003c/td\u003e\n      \u003ctd\u003e\u003cimg src=\"https://raw.githubusercontent.com/DonnC/docxtpl/main/example/demo/docxtpl-filled.png\"\u003e\u003c/td\u003e\n   \u003c/tr\u003e\n\u003c/table\u003e\n\n## Usage\nFirst import the `docxtpl` plugin in your dart file\n```dart\nimport 'package:docxtpl/docxtpl.dart';\n``` \n\nMake sure you have created your `.docx` template file and saved it either in your `asset folder` or `remote` or in your device `local storage`.\n\n- `docxtpl` can work with generated templates from `asset folder`, `remote file` and `device storage` file.\n\n\n### Example: Generate from .docx tpl in asset folder\nMake sure you have added your .docx word tpl asset file in `pubspec.yaml` file\n```dart\n   final DocxTpl docxTpl = DocxTpl(\n      docxTemplate: 'assets/invite.docx',  // path where tpl file is\n      isAssetFile: true,      // flag to true for tpl file from asset\n    );\n\n   // fields corresponding to merge fields found to fill the template with\n   var templateData = {\n    'name': 'Dart | Flutter Developer',\n    'event': 'DocxTpl Plugin Contribution',\n    'venue': 'Github',\n    'time': 'Anytime',\n    'row': '1',\n    'guest': 'Flutter',\n    'sender': '@DonnC',\n  };\n\n   var response = await docxTpl.parseDocxTpl();\n\n   print(response.mergeStatus);\n   print(response.message);\n\n    if(response.mergeStatus == MergeResponseStatus.Success) {\n      // success, proceed\n      // get merge fields extracted by the plugin to know which fields to fill\n      var fields = docxTpl.getMergeFields();\n\n      print('Template file fields found: ');\n      print(fields);\n\n      await docxTpl.writeMergeFields(data: templateData);\n\n      var savedFile = await docxTpl.save('invitation.docx');\n    }\n```\n\n## Features \u0026 TODO\n- [✔]  Simple templating\n- [❌] able to pick complex tags\n- [❌] add more complex tag formats\n- [❌] able to populate a table\n- [❌] ability to insert images\n- [❌] ability to add custom file formatting (rich-text)\n- and more `...`\n\n## Api Changes\nApi changes are available on [CHANGELOG](CHANGELOG.md)\n\n### Support\n- This plugin offers a very basic word-templating with simple tags\n- It was tested with a simple word document\n- I really appreciate more support on this, hopefully it can be the ultimate go-to for working with word documents in flutter\n- Contributions are welcome with open hands\n\n\n## references\n- A detailed article about .docx word documents [READ HERE](https://www.toptal.com/xml/an-informal-introduction-to-docx)\n- `docxtpl` is a inspiration from python libraries that does almost the same i.e word document templating. It is inspired mainly from [python-docx-template](https://github.com/elapouya/python-docx-template) and [docx-mailmerge](https://github.com/Bouke/docx-mailmerge).\n- A detailed article on how [docx-mailmerge](https://pbpython.com/python-word-template.html) works (`python`)\n- Jinja2 templating [jinja](https://palletsprojects.com/p/jinja/)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdonnc%2Fdocxtpl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdonnc%2Fdocxtpl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdonnc%2Fdocxtpl/lists"}