nguyenthenguyen / docx Goto Github PK
View Code? Open in Web Editor NEWSimple Google Go (Golang) library for replacing text in Microsoft Word (.docx) file
License: MIT License
Simple Google Go (Golang) library for replacing text in Microsoft Word (.docx) file
License: MIT License
Hi, thanks for creating this awesome library, how write a newline and dynamic table using this library?
Hi, thank you for your awesome work!
It would be nice to have a ReplaceImage()
function, the function could be like the following:
func ReplaceImage(oldFilePath, newFilePath)
In which the oldFilePath
is the image file name inside word/media
, and the newFilePath
is the file path we want to replace into.
And so far I've figured out there will be 3 things to do to replace an image:
word/media/...
and overwrite the old file.<Relationship Id="..." Type="..." Target="media/image1.png"/>
line according to the new image file format.[Content_Types].xml
if it doesn't contain the corresponding file type.there is a need to replace header and footer text
If you try to replace an image, it is placed in the same place, with the same width and the same height as the original in the document. The problem is when you try to replace an image with different width or height, it looks flattened.
Hi Ijust wanted to use your library, but noticed, after I replaced the variables/placeholders I can not export it to PDF.
If this package does not provide this, is there another package, that is able to do so?
If so, is it possible to to so stateless? As I dont ever want to store the file, just to read and delete it again.
So would be cool if you would add the the option to export the DOCX as PDF.
Thanks in advance!
This is a great simple library. Thanks @nguyenthenguyen
There is no license for this project. Would you like to add one?
I find the content is not right, the word has been spitted.
二、租赁房屋结构:house_body 面积:house_size平方米
the content :
二、租赁房屋结构:</w:t></w:r><w:proofErr w:type="spellStart"/><w:r w:rsidR="00B9317A"><w:rPr><w:rFonts w:ascii="方正仿宋_GBK" w:eastAsia="方正仿宋_GBK" w:hint="eastAsia"/><w:sz w:val="24"/></w:rPr><w:t>ho</w:t></w:r><w:r w:rsidR="00B9317A"><w:rPr><w:rFonts w:ascii="方正仿宋_GBK" w:eastAsia="方正仿宋_GBK"/><w:sz w:val="24"/></w:rPr><w:t>use_body</w:t></w:r><w:proofErr w:type="spellEnd"/><w:r w:rsidR="00C32FC4"><w:rPr><w:rFonts w:ascii="方正仿宋_GBK" w:eastAsia="方正仿宋_GBK" w:hint="eastAsia"/><w:sz w:val="24"/></w:rPr><w:t xml:space="preserve"> </w:t></w:r><w:r w:rsidR="00723995"><w:rPr><w:rFonts w:ascii="方正仿宋_GBK" w:eastAsia="方正仿宋_GBK" w:hint="eastAsia"/><w:sz w:val="24"/></w:rPr><w:t>面积:</w:t></w:r><w:r w:rsidR="00B9317A"><w:rPr><w:rFonts w:ascii="方正仿宋_GBK" w:eastAsia="方正仿宋_GBK" w:hint="eastAsia"/><w:sz w:val="24"/></w:rPr><w:t>ho</w:t></w:r><w:r w:rsidR="00B9317A"><w:rPr><w:rFonts w:ascii="方正仿宋_GBK" w:eastAsia="方正仿宋_GBK"/><w:sz w:val="24"/></w:rPr><w:t>use_body</w:t></w:r><w:bookmarkStart w:id="0" w:name="_GoBack"/><w:bookmarkEnd w:id="0"/><w:r><w:rPr><w:rFonts w:ascii="方正仿宋_GBK" w:eastAsia="方正仿宋_GBK" w:hint="eastAsia"/><w:sz w:val="24"/></w:rPr><w:t>平方米</w:t></w:r></w:p><w:p w:rsidR="00AE4936" w:rsidRDefault="00AE4936" w:rsidP="00AE4936"><w:pPr><w:spacing w:line="460" w:lineRule="exact"/><w:ind w:firstLine="630"/><w:rPr><w:rFonts w:ascii="方正仿宋_GBK" w:eastAsia="方正仿宋_GBK"/><w:sz w:val="24"/></w:rPr></w:pPr><w:r><w:rPr><w:rFonts w:ascii="方正仿宋_GBK" w:eastAsia="方正仿宋_GBK" w:hint="eastAsia"/><w:sz w:val="24"/></w:rPr><w:t>
what is wrong with it ?
Hey I used your library and added "text/template" on top of it. Not sure if it could be merged upstream or this is a different project completely. Thoughts on the update??
When replacing strings, passing keys overrides the problem, for example cover and str_cover. The string to be searched is cover to replace aaabbbcccc , and there is also another string to be replaced, str_cover to be replaced with qqqwwweeee. Although the replacement can generate a docx file, opening it with Office fails, and the file content is problematic. Please consider this issue accordingly.
It would be useful to have a method to extract the plain text
Is there a way to create/add newline? I tried several ways to add new line to a text and replace to the docx file. But every whitespace becomes a space.
package main
import (
"fmt"
"github.com/nguyenthenguyen/docx"
)
func main() {
// Read from docx file
r, err := docx.ReadDocxFile("./a.docx")
// Or read from memory
// r, err := docx.ReadDocxFromMemory(data io.ReaderAt, size int64)
// Or read from a filesystem object:
// r, err := docx.ReadDocxFromFS(file string, fs fs.FS)
if err != nil {
fmt.Println("----")
panic(err)
fmt.Println("====")
}
docx1 := r.Editable()
// Replace like https://golang.org/pkg/strings/#Replace
docx1.Replace("OS_CPU", "OK", -1)
docx1.WriteToFile("./a.docx")
r.Close()
}
panic: zip: not a valid zip file
goroutine 1 [running]:
main.main()
D:/Go/src/testdoc/testdoc.go:21 +0x1a5
exit status 2
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.