You must Sign In to post a response.
Category: General
#765694
Hi
Interop dll should be only converted word template to C#. C# to word template
Name : Dotnet Developer-2015
Email Id : kumaraspcode2009@gmail.com
'Not by might nor by power, but by my Spirit,' says the LORD Almighty.
Interop dll should be only converted word template to C#. C# to word template
Name : Dotnet Developer-2015
Email Id : kumaraspcode2009@gmail.com
'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.
https://msdn.microsoft.com/en-us/library/office/bb448854.aspx
By Nathan
Direction is important than speed
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.
https://msdn.microsoft.com/en-us/library/office/bb448854.aspx
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:
http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=5124
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;
namespaceGenerateDocumentFromTemplate
{
class Program
{
static void Main(string[] args)
{
string destinationFile = Path.Combine(Environment.CurrentDirectory, "SampleDocument.docx");
string sourceFile = Path.Combine(Environment.CurrentDirectory, "Sample.dotx");
try
{
// 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
document.ChangeDocumentType(DocumentFormat.OpenXml.WordprocessingDocumentType.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
documentSettingPart1.Settings.Append(attachedTemplate1);
// Add an ExternalRelationShip of type AttachedTemplate.
// Specify the path of template and the relationship ID
documentSettingPart1.AddExternalRelationship("http://schemas.openxmlformats.org/officeDocument/2006/relationships/attachedTemplate", new Uri(sourceFile, UriKind.Absolute), "relationId1?);
// Save the document
mainPart.Document.Save();
Console.WriteLine("Document generated at " + destinationFile);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
Console.WriteLine("\nPress Enter to continue…");
Console.ReadLine();
}
}
}
}
Download and install Open XML SDK 2.0 from the following location:
http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=5124
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;
namespaceGenerateDocumentFromTemplate
{
class Program
{
static void Main(string[] args)
{
string destinationFile = Path.Combine(Environment.CurrentDirectory, "SampleDocument.docx");
string sourceFile = Path.Combine(Environment.CurrentDirectory, "Sample.dotx");
try
{
// 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
document.ChangeDocumentType(DocumentFormat.OpenXml.WordprocessingDocumentType.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
documentSettingPart1.Settings.Append(attachedTemplate1);
// Add an ExternalRelationShip of type AttachedTemplate.
// Specify the path of template and the relationship ID
documentSettingPart1.AddExternalRelationship("http://schemas.openxmlformats.org/officeDocument/2006/relationships/attachedTemplate", new Uri(sourceFile, UriKind.Absolute), "relationId1?);
// Save the document
mainPart.Document.Save();
Console.WriteLine("Document generated at " + destinationFile);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
Console.WriteLine("\nPress Enter to continue…");
Console.ReadLine();
}
}
}
}
#766559
HI,
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);
doc.Activate();
Regards,
Karunanidhi.K
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);
doc.Activate();
Regards,
Karunanidhi.K
#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
https://msdn.microsoft.com/en-us/library/office/bb448854.aspx
By Nathan
Direction is important than speed
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
https://msdn.microsoft.com/en-us/library/office/bb448854.aspx
By Nathan
Direction is important than speed
Return to Return to Discussion Forum