You must Sign In to post a response.
  • Category: General

    How to convert a word template with controls to word document in C# without using Interop

    I am trying to convert a word template containing various controls to a word document without using Interop, My requirement is I am not able to find all the controls of my word template.
  • #765694

    Interop dll should be only converted word template to C#. C# to word template

    Name : Dotnet Developer-2015
    Email Id :

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #765699
    To convert template from to word document you have to use the Interop.dll.
    You can try some of the third party tools also.
    Can you try Open XML SDK 2.5 for Office. This is free from microsoft. Try this.

    By Nathan
    Direction is important than speed

  • #765722
    creating docx files from template files without using interop.dll

    Download and install Open XML SDK 2.0 from the following location:

    Open Visual Studio 2010 and create a new Console application in C#
    Add a reference to DocumentFormat.OpenXml and WindowsBase assemblies.
    Create a document in the current directory with the name "Sample.dotx"
    Replace the code with the one given below and run it:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using DocumentFormat.OpenXml.Wordprocessing;
    using DocumentFormat.OpenXml.Packaging;
    using System.IO;

    class Program
    static void Main(string[] args)
    string destinationFile = Path.Combine(Environment.CurrentDirectory, "SampleDocument.docx");
    string sourceFile = Path.Combine(Environment.CurrentDirectory, "Sample.dotx");
    // Create a copy of the template file and open the copy
    File.Copy(sourceFile, destinationFile, true);
    using (WordprocessingDocument document = WordprocessingDocument.Open(destinationFile, true))
    // Change the document type to Document

    // Get the MainPart of the document
    MainDocumentPart mainPart = document.MainDocumentPart;

    // Get the Document Settings Part
    DocumentSettingsPart documentSettingPart1 = mainPart.DocumentSettingsPart;

    // Create a new attachedTemplate and specify a relationship ID
    AttachedTemplate attachedTemplate1 = new AttachedTemplate() { Id = "relationId1? };

    // Append the attached template to the DocumentSettingsPart

    // Add an ExternalRelationShip of type AttachedTemplate.
    // Specify the path of template and the relationship ID
    documentSettingPart1.AddExternalRelationship("", new Uri(sourceFile, UriKind.Absolute), "relationId1?);

    // Save the document

    Console.WriteLine("Document generated at " + destinationFile);
    catch (Exception ex)
    Console.WriteLine("\nPress Enter to continue…");

  • #766559
    Kindly use the following codes,

    Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();

    object oMissing = System.Reflection.Missing.Value;

    word.Visible = false;
    word.ScreenUpdating = false;
    string fileName = @"c:\OUTPUT\test.docx");
    Document doc = word.Documents.Open(filename, ref oMissing,
    ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
    ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
    ref oMissing, ref oMissing, ref oMissing, ref oMissing);


  • #766566
    Try some third party tools.
    Open XML is the one of the solution for your requirment.
    XML SDK 2.5 for Office is free from microsoft.
    you can try that. Following is the link for doing that

    By Nathan
    Direction is important than speed

  • Sign In to post your comments