- Code: Select all
var document = new Document();
document.LoadFromFile(@"C:\Users\eddy\OneDrive\Documentos\MyDocument.docx");
Section s = document.Sections[0];
Paragraph p = s.Paragraphs[1];
//get strings to replace
Dictionary<string, string> dictReplace = GetReplaceDictionary();
//Replace text
ParagraphStyle style = new ParagraphStyle(document);
foreach (KeyValuePair<string, string> kvp in dictReplace)
{
document.Replace(kvp.Key, kvp.Value, true, true);
style.Name = "FontStyle";
style.CharacterFormat.FontName = "Arial";
style.CharacterFormat.FontSize = 12;
document.Styles.Add(style);
p.ApplyStyle(style.Name);
}
//Save doc file.
document.SaveToFile(@"C:\Users\edgar\Desktop\CONSTANCIAS_EMPLEADOS\" + txtNombre.Text.Trim() + ".docx", FileFormat.Docx);
document.Close();
Dictionary<string, string> GetReplaceDictionary()
{
Dictionary<string, string> replaceDict = new Dictionary<string, string>();
replaceDict.Add("#name#", txtNombre.Text.Trim());
replaceDict.Add("#denomination#", txtDenominacion.Text.Trim());
replaceDict.Add("#resume#", txtResumen.Text.Trim());
return replaceDict;
}
but I can't set the format I want, in this case arial format
How can i get that format, I hope can you help me
thanks