Code Monkey home page Code Monkey logo

Comments (5)

joeblew99 avatar joeblew99 commented on May 13, 2024

If your curious on the fix, i tried this and it worked perfectly for the use case

https://github.com/nguyenthenguyen/docx

package main

import (
	"github.com/nguyenthenguyen/docx"
)

func main() {
	r, err := docx.ReadDocxFile("./Test.docx")
	if err != nil {
		panic(err)
	}
	docx1 := r.Editable()
	// Replace like https://golang.org/pkg/strings/#Replace

	docx1.Replace("Test", "Test-BG", -1)
	docx1.Replace("old_1_2", "new_1_2", -1)
	docx1.ReplaceHeader("out with the old", "in with the new")
	docx1.ReplaceFooter("Change This Footer", "new footer")
	docx1.WriteToFile("./Test-out.docx")

	r.Close()
}

from unioffice.

tbaliance avatar tbaliance commented on May 13, 2024

@joeblew99 That package unpacks the XML and does a search and replace. This one fully parses the documents to allow more advanced editing. The problem with this one is we aren't handling the image filename correctly. In the document it's 'word/media/image2.png', even though it's the only image and when saving we are writing it back out as 'word/media/image1.png' without changing the relationship file to reflect the new name. It should be a straight forward fix, we handle the renames for other types but skipped it for images so far.

from unioffice.

tbaliance avatar tbaliance commented on May 13, 2024

@joeblew99 I rolled a quick fix into a branch I was about to merge in. I'l add a test for it later, but this should fix your issue. Feel free to re-open if you still run any problems.

from unioffice.

tbaliance avatar tbaliance commented on May 13, 2024

@joeblew99 Also, do you mind if I check your test.docx in and use it as a test file?

from unioffice.

joeblew99 avatar joeblew99 commented on May 13, 2024

from unioffice.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.