Aspose generated doc file turns underscores into white space for some users

187 Views Asked by At

I am updating archaic code that creates memos. The code was written to use bookmarks inside of manually created template.doc files that aspose can write to. The problem comes from this chunk of code.

foreach (Addressee infoAddressee in ConfigManager.GetConfig().Addressees)
                    {
                        if (infoAddressee.Abbreviation == Memo.AddresseeAbbr.ToUpper() &&
                            infoAddressee.NeedsThisLine)
                        {
                            WriteMeString = "FOO BARR ________";
                            break;
                        }
                    }

                    if (WriteMeString != "")
                    {
                        builder.MoveToBookmark("BOOKMARK");
                        builder.Write(WriteMeString);
                    }
                }

This works for me, but the two people who have tested this chunk of code have the "FOO BARR _______" line appear as "FOO BARR " the seven underlines are replaced with spaces(the spacing exists on the word doc, but Stack overflow concatenates consecutive spaces). I am not sure what could cause this. To test we need to copy the file from the remote dev environment into our local environment, I believe this to be the source of the issue, but i do not know for sure.

What I have already tried:

  1. The testers and me are supplying the exact same input for the document.
  2. The testers and I had a slightly different way to save the document and copy paste it over to the local environment, but doing it my way did not change anything.

I am unsure of what could do this for some users but not for others, any suggestions for things i could check out, be it literature with information on the subject or proposed solutions, would be greatly appreciated

1

There are 1 best solutions below

0
On

I checked the scenario on my side and cannot reproduce the problem. Underscores are properly displayed in the output document. Here are few things to try.

  1. Try setting bookmark text instead of moving to it and writing text.
doc.Range.Bookmarks["BOOKMARK"].Text = WriteMeString;
  1. Try checking whether string is written correctly into the document.
builder.MoveToBookmark("BOOKMARK");
builder.Write("FOO BARR ________");

Assert.AreEqual("FOO BARR ________", builder.Document.Range.Bookmarks["BOOKMARK"].Text);

using (MemoryStream ms = new MemoryStream())
{
    builder.Document.Save(ms, SaveFormat.Doc);
    ms.Position = 0;

    Document tempDoc = new Document(ms);

    Assert.AreEqual("FOO BARR ________", tempDoc.Range.Bookmarks["BOOKMARK"].Text);
}
  1. Compare the documents produced on your side and on the testers side yourself (I suppose, you have already done this, but just in case). Probably the documents are correct, but there is difference in viewer used on your and testers side.

Disclosure: I work at Aspose.Words team.