1

I have a word template and I want to create doc file from that, also I want to replace add data in place of bookmarks present in the template. I have been able to create a doc file, but I am not able to understand, how to add data in place of bookmarks? My code till now:

private void CreateSampleWordDocument()
    {
        string sourceFile = Path.Combine(Environment.CurrentDirectory, "GeneralWelcomeLetter.dotx");
        string destinationFile = Path.Combine(Environment.CurrentDirectory, "Sample.docx");
        try
        {
            File.Copy(sourceFile, destinationFile, true);
            WordprocessingDocument document = WordprocessingDocument.Open(destinationFile, true);
            document.ChangeDocumentType(DocumentFormat.OpenXml.WordprocessingDocumentType.Document);

            MainDocumentPart mainPart = document.MainDocumentPart;

            DocumentSettingsPart documentSettingPart1 = mainPart.DocumentSettingsPart;

            AttachedTemplate attachedTemplate1 = new AttachedTemplate() { Id = "relationId1" };

            documentSettingPart1.Settings.Append(attachedTemplate1);
        }
        catch
        {
        }
    }

Now to add data from database in place of bookmarks?

Incredible
  • 3,495
  • 8
  • 49
  • 77

0 Answers0