I need to create a program that generates a document in Word, I found these methods but I do not know how to call the Word file (I already have the Word template made). How do I call that word template within those methods? Can someone give me a suggestion on how I do it, thank you very much
private void FindAndReplace(Microsoft.Office.Interop.Word.Application wordApp, Object findText, object replaceWithText)
{
object matchCase = true;
object matchWholeWord = true;
object matchWildCards = false;
object matchsoundLike = false;
object nmatchAllForms = false;
object forward = true;
object format = false;
object matchKashida = false;
object matchDiactitics = false;
object matchAlefHamza = false;
object matchControl = false;
object read_Only = false;
object visible = true;
object replace = 2;
object wrap = 1;
wordApp.Selection.Find.Execute(ref findText,
ref matchCase, ref matchWholeWord,
ref matchWildCards, ref matchsoundLike,
ref nmatchAllForms, ref forward,
ref wrap, ref format, ref replaceWithText,
ref replace, ref matchKashida,
ref matchDiactitics, ref matchAlefHamza,
ref matchControl);
}
string pathImage = null;
private void CreateWordDocument(object filename, object savaAs, object image)
{
object missing = Missing.Value;
string tempPath = null;
Word.Application wordApp = new Word.Application();
Word.Document aDoc = null;
if (File.Exists((String)filename))
{
DateTime today = DateTime.Now;
object readOnly = false;
object isVisible = false;
wordApp.Visible = false;
aDoc = wordApp.Documents.Open(ref filename, ref missing, ref readOnly,
ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing);
aDoc.Activate();
//Find and replace
this.FindAndReplace(wordApp, "<name>", "juan martin");
}
else
{
MessageBox.Show("El archivo no existe");
}
//Save as : filename
aDoc.SaveAs2(ref savaAs, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing);
//Close Document:
aDoc.Close(ref missing, ref missing, ref missing);
File.Delete(tempPath);
MessageBox.Show("Carta Generada");
}