Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Office2007 is not supported #401

Open
liz-lizhan opened this issue Jun 5, 2020 · 6 comments
Open

Office2007 is not supported #401

liz-lizhan opened this issue Jun 5, 2020 · 6 comments

Comments

@liz-lizhan
Copy link

Description

Expected Behavior

Actual Behavior

Please include a reproducible code snippet or document attachment that
demonstrates the issue.

@github-actions
Copy link

github-actions bot commented Jun 5, 2020

Welcome! Thanks for posting your first issue. The way things work here is that while customer issues are prioritized,
other issues go into our backlog where they are assessed and fitted into the roadmap when suitable.
If you need to get this done, consider buying a license which also enables you to use it in your commercial products.
More information can be found on https://unidoc.io/

@gunnsth
Copy link
Contributor

gunnsth commented Jun 7, 2020

@lz-2019 Can you please fill out the issue form? And provide files needed to reproduce the problem. Office2007 is expected to work.

@gunnsth gunnsth added eval Evaluate pending Awaiting feedback labels Jun 7, 2020
@liz-lizhan
Copy link
Author

Problem recovery

Platform: win7 and office2007

demo

func main() {
	doc, err := document.Open("document.docx")
	if err != nil {
		log.Fatalf("error opening document: %s", err)
	}

	paragraphs := []document.Paragraph{}
	for _, p := range doc.Paragraphs() {
		paragraphs = append(paragraphs, p)
	}

	// This sample document uses structured document tags, which are not common
	// except for in document templates.  Normally you can just iterate over the
	// document's paragraphs.
	for _, sdt := range doc.StructuredDocumentTags() {
		for _, p := range sdt.Paragraphs() {
			paragraphs = append(paragraphs, p)
		}
	}

	for _, p := range paragraphs {
		for _, r := range p.Runs() {
			switch r.Text() {
			case "FIRST NAME":
				// ClearContent clears both text and line breaks within a run,
				// so we need to add the line break back
				r.ClearContent()
				r.AddText("John ")
				r.AddBreak()

				para := doc.InsertParagraphBefore(p)
				para.AddRun().AddText("Mr.")
				para.SetStyle("Name") // Name is a default style in this template file

				para = doc.InsertParagraphAfter(p)
				para.AddRun().AddText("III")
				para.SetStyle("Name")

			case "LAST NAME":
				r.ClearContent()
				r.AddText("Smith")
			case "Address | Phone | Email":
				r.ClearContent()
				r.AddText("111 Rustic Rd | 123-456-7890 | jsmith@smith.com")
			case "Date":
				r.ClearContent()
				r.AddText(time.Now().Format("Jan 2, 2006"))
			case "Recipient Name":
				r.ClearContent()
				r.AddText("Mrs. Smith")
				r.AddBreak()
			case "Title":
				// we remove the title content entirely
				p.RemoveRun(r)
			case "Company":
				r.ClearContent()
				r.AddText("Smith Enterprises")
				r.AddBreak()
			case "Address":
				r.ClearContent()
				r.AddText("112 Rustic Rd")
				r.AddBreak()
			case "City, ST ZIP Code":
				r.ClearContent()
				r.AddText("San Francisco, CA 94016")
				r.AddBreak()
			case "Dear Recipient:":
				r.ClearContent()
				r.AddText("Dear Mrs. Smith:")
				r.AddBreak()
			case "Your Name":
				r.ClearContent()
				r.AddText("John Smith")
				r.AddBreak()

				run := p.InsertRunBefore(r)
				run.AddText("---Before----")
				run.AddBreak()
				run = p.InsertRunAfter(r)
				run.AddText("---After----")

			default:
				fmt.Println("not modifying", r.Text())
			}
		}
	}

	doc.SaveToFile("edit-document.docx")
}

The generated edit-document.docx is opened in office2007 under win7
深度截图_选择区域_20200608110628

@alecte
Copy link

alecte commented Jun 11, 2020

I can confirm that it does not seem to work with Office 2007.

Office versions tested:
Microsoft(R) Office Word 2007 (12.0.6787.5000) SP3 MSO (12.0.6785.5000)
Microsoft(R) Office Excel 2007 (12.0.6787.5000) SP3 MSO (12.0.6785.5000)

Windows version info:
Microsoft Windows Version 1909 (SO Compilation 18363.900)

Both Windows and Office are in spanish, in case that matters.

Steps to reproduce: open any file in the _examples dir that was generated by this library. For example, _examples\document\fill-out-form\filled-form.docx. (Note: opening the file form.docx in the same directory works).

What happened: an error dialog appears saying that the file cannot be opened because there's problems with the content. Clicking on details says that the file is damaged and cannot be opened.

After that Word says that it found "unreadable content" (dunno the exact wording in english) and asks if you trust the origin of the document and you want to recover the content of the document. Selecting yes results in another error dialog that says that Office could not recover the document.

Related issues: #217 #89

@gunnsth you said that Office 2007 is expected to work, however issue 217 was closed just saying that 2007 uses a different format, so it is really expected to work? Note at least reading 2007 files works, see the fill-out-form example where the input file works but not the output.

In case it's not gonna be supported (which I can understand) could it be possible to mention somewhere the minimum required version of Office?

@gunnsth gunnsth added document repro and removed pending Awaiting feedback labels Oct 11, 2020
@gunnsth
Copy link
Contributor

gunnsth commented Oct 11, 2020

@lz-2019 Can you please attach the document.docx and output edit-document.docx so this can be reproduced?
Thanks.

@gunnsth gunnsth added the pending Awaiting feedback label Oct 11, 2020
@gunnsth
Copy link
Contributor

gunnsth commented Oct 11, 2020

@alecte Thanks for reporting as well. As a user I expect Office 2007 to work, so I do consider this a bug. We would like Office 2007 to work. If we decide to drop support for some versions, we will specify it. Note that actually supporting older version can be troublesome, but we will investigate this and see what we come up with. We have been working on something such as handling AlternateContent tags which is related to this. Hopefully we can come up with a generic way to enable this.

@gunnsth gunnsth removed the pending Awaiting feedback label Oct 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants