{"id":18043469,"url":"https://github.com/fumiama/go-docx","last_synced_at":"2025-04-12T23:34:20.981Z","repository":{"id":93057699,"uuid":"598992077","full_name":"fumiama/go-docx","owner":"fumiama","description":"One of the most functional libraries to partially read and write .docx files (a.k.a. Microsoft Word documents or ECMA-376 Office Open XML) in Go.","archived":false,"fork":false,"pushed_at":"2024-12-31T15:31:24.000Z","size":1583,"stargazers_count":189,"open_issues_count":10,"forks_count":34,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-12T23:34:10.773Z","etag":null,"topics":["docx","docx-converter","docx-files","docx-generator","openxml","openxml-format","openxml-sdk","openxml-word","word","xml"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fumiama.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-08T08:19:23.000Z","updated_at":"2025-04-12T15:49:03.000Z","dependencies_parsed_at":"2023-11-16T13:47:29.156Z","dependency_job_id":"61563a49-4a21-421a-89f6-b83c7fa3d79a","html_url":"https://github.com/fumiama/go-docx","commit_stats":{"total_commits":129,"total_committers":9,"mean_commits":"14.333333333333334","dds":"0.22480620155038755","last_synced_commit":"f7d29bb5c37163649becb3d85d1d8a48faa7de91"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fumiama%2Fgo-docx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fumiama%2Fgo-docx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fumiama%2Fgo-docx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fumiama%2Fgo-docx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fumiama","download_url":"https://codeload.github.com/fumiama/go-docx/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248647259,"owners_count":21139081,"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":["docx","docx-converter","docx-files","docx-generator","openxml","openxml-format","openxml-sdk","openxml-word","word","xml"],"created_at":"2024-10-30T17:08:47.515Z","updated_at":"2025-04-12T23:34:20.949Z","avatar_url":"https://github.com/fumiama.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Docx library\n\nOne of the most functional libraries to read and write .docx (a.k.a. Microsoft Word documents or ECMA-376 Office Open XML) files in Go.\n\nThis is a variant optimized and expanded by fumiama. The original repo is [gonfva/docxlib](https://github.com/gonfva/docxlib).\n\n## Introduction\n\n\u003e As part of my work for [Basement Crowd](https://www.basementcrowd.com) and [FromCounsel](https://www.fromcounsel.com), we were in need of a basic library to manipulate (both read and write) Microsoft Word documents.\n\u003e \n\u003e The difference with other projects is the following:\n\u003e - [UniOffice](https://github.com/unidoc/unioffice) is probably the most complete but it is also commercial (you need to pay). It also very complete, but too much for my needs.\n\u003e - [gingfrederik/docx](https://github.com/gingfrederik/docx) only allows to write.\n\u003e \n\u003e There are also a couple of other projects [kingzbauer/docx](https://github.com/kingzbauer/docx) and [nguyenthenguyen/docx](https://github.com/nguyenthenguyen/docx)\n\u003e \n\u003e [gingfrederik/docx](https://github.com/gingfrederik/docx) was a heavy influence (the original structures and the main method come from that project).\n\u003e \n\u003e However, those original structures didn't handle reading and extending them was particularly difficult due to Go xml parser being a bit limited including a [6 year old bug](https://github.com/golang/go/issues/9519).\n\u003e \n\u003e Additionally, my requirements go beyond the original structure and a hard fork seemed more sensible.\n\u003e \n\u003e The plan is to evolve the library, so the API is likely to change according to my company's needs. But please do feel free to send patches, reports and PRs (or fork).\n\u003e \n\u003e In the mean time, shared as an example in case somebody finds it useful.\n\nThe Introduction above is copied from the original repo. I had evolved that repo again to fit my needs. Here are the supported functions now.\n\n- [x] Parse and save document\n- [x] Edit text (color, size, alignment, link, ...)\n- [x] Edit picture\n- [x] Edit table\n- [x] Edit shape\n- [x] Edit canvas\n- [x] Edit group\n\n## Quick Start\n```bash\ngo run cmd/main/main.go -u\n```\nAnd you will see two files generated under `pwd` with the same contents as below.\n\n\u003ctable\u003e\n\t\u003ctr\u003e\n\t\t\u003ctd align=\"center\"\u003e\u003cimg src=\"https://user-images.githubusercontent.com/41315874/223348099-4a6099d2-0fec-4e13-92a7-152c00bc6f6b.png\"\u003e\u003c/td\u003e\n\t\t\u003ctd align=\"center\"\u003e\u003cimg src=\"https://user-images.githubusercontent.com/41315874/223349486-e78ac0f1-c879-4888-9110-ea4db2590241.png\"\u003e\u003c/td\u003e\n\t\u003c/tr\u003e\n\t\u003ctr\u003e\n\t\t\u003ctd align=\"center\"\u003ep1\u003c/td\u003e\n\t\t\u003ctd align=\"center\"\u003ep2\u003c/td\u003e\n\t\u003c/tr\u003e\n\u003c/table\u003e\n\n## Use Package in your Project\n```bash\ngo get -d github.com/fumiama/go-docx@latest\n```\n### Generate Document\n```go\npackage main\n\nimport (\n\t\"os\"\n\t\"strings\"\n\n\t\"github.com/fumiama/go-docx\"\n)\n\nfunc main() {\n\tw := docx.New().WithDefaultTheme()\n\t// add new paragraph\n\tpara1 := w.AddParagraph()\n\t// add text\n\tpara1.AddText(\"test\").AddTab()\n\tpara1.AddText(\"size\").Size(\"44\").AddTab()\n\tf, err := os.Create(\"generated.docx\")\n\t// save to file\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\t_, err = w.WriteTo(f)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\terr = f.Close()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n}\n```\n### Parse Document\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strings\"\n\n\t\"github.com/fumiama/go-docx\"\n)\n\nfunc main() {\n\treadFile, err := os.Open(\"file2parse.docx\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tfileinfo, err := readFile.Stat()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tsize := fileinfo.Size()\n\tdoc, err := docx.Parse(readFile, size)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tfmt.Println(\"Plain text:\")\n\tfor _, it := range doc.Document.Body.Items {\n\t\tswitch it.(type) {\n\t\tcase *docx.Paragraph, *docx.Table: // printable\n\t\t\tfmt.Println(it)\n\t\t}\n\t}\n}\n```\n\n## License\n\nAGPL-3.0. See [LICENSE](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffumiama%2Fgo-docx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffumiama%2Fgo-docx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffumiama%2Fgo-docx/lists"}