chrisfcarroll / MailMerge

Merge component for OfficeOpenXml .docx (i.e. Microsoft Word) documents
GNU General Public License v3.0
19 stars 7 forks source link

Issue with some MergeFields #1

Closed acmngmbh closed 4 years ago

acmngmbh commented 5 years ago

Hi, i am trying to make use of your library in my project, but encountered the following problem. If a merge field is split in multiply w:instrText-Elements, merge process fails.

<w:instrText xml:space="preserve"> MERGEFIELD </w:instrText></w:r><w:r w:rsidR="007B7BF2"><w:rPr><w:lang w:val="en-US"/></w:rPr><w:instrText>MailingAddress</w:instrText></w:r><w:r w:rsidR="007B7BF2" w:rsidRPr="007B7BF2"><w:rPr><w:lang w:val="en-US"/></w:rPr><w:instrText>.</w:instrText></w:r><w:r w:rsidR="007B7BF2"><w:rPr><w:lang w:val="en-US"/></w:rPr><w:instrText>street</w:instrText></w:r>

Do you have an idea how to fix this? Best Regards

chrisfcarroll commented 5 years ago

I suspect it would be a code change that I wouldn't get to anytime soon :-( Although I can have a look later this week if you have a short example.

But I think you can fix it faster if it's a small number of source documents by editing your document to put the pieces back together into one w:instrText, i.e. replace most of the snippet you pasted with

<w:r><w:instrText xml:space="preserve">MERGEFIELD MailingAddress.street</w:instrText></w:r>

being careful when editing the xml to not mismatch the tags.

acmngmbh commented 5 years ago

Here is a sample file: https://www.dropbox.com/s/3scxuu2cjzjp6a1/Account.docx?dl=0 You can see the problem in the last two fields. By now, I did not find out, why Word is splitting these fields.

chrisfcarroll commented 5 years ago

I've pushed changes which I think handle your doc correctly. Try it again?