view raw
endovitskiiy endovitskiiy - 6 months ago 48
C# Question

Word document. Replacement markers

There is a file format .docx. In this file there are markers, for example:





Need to replace markers with values. Values come into the function from the js.

I use c#.

Any suggestions.


So based on what you've told me, I'm assuming that you have something like this:

using System;
using System.IO;

class json
    string FirstName = "";
    string MiddleName = "";
    string LastName = "";
    string FullName = FirstName + " " + MiddleName + " " + LastName;

    FileStream fStream = new FileStream("fileName.docx", FileMode.Open, 
                                         FileAccess.Write, FileAshar.Write);

    public json()

    public void SendNameToFile(string fName)
         fStream.Write(fName + "\n");

Again, your question is kind of vague. I'm not sure what you mean by Markers, but if you mean that you have fields in your .docx displaying [FirstName], [MiddleName, & [LastName], and you want to sub those out with your string variable values, then you have to search through your .docx and look for that particular char[] of your Markers and then re-assign those with your variables.

You can check out this link on MSDN:

"How to: Programmatically Search for and Replace Text in Documents"