Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Tue Mar 03, 2020 7:09 pm

Hi, i have a question, How can I set a text style to my document? this is my code:
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

eddy12345
 
Posts: 1
Joined: Fri Feb 07, 2020 6:06 pm

Wed Mar 04, 2020 2:33 am

Hello,

Thanks for your inquiry.
To help us investigate your issue more accurately, please provide your input file as well as your desired output. You could upload here or send them to us([email protected]) via email. Thanks in advance.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Wed Mar 11, 2020 8:53 am

Hello,

Greetings from E-iceblue!
How is your issue now? Could you please provide the information I mentioned above to help us further investigate it?
Thanks in advance.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Return to Spire.Doc

cron