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.

Thu Jul 25, 2019 6:26 pm

HI
I need to replace some text from one word file with html text (from database).
Here is my code:
Code: Select all
Document document = new Document();             
                document.LoadFromFile(@"c:\bootstraplocal\documentos_word\Ficha do cliente.docx");
                document.Replace("nome_cliente",txtNomeAltera.Text, false, true);
                document.Replace("cliente_numero_contribuinte", txtContribuinteAltera.Text, false, true);
                document.Replace("cliente_telemovel", txtTelefoneAltera.Text, false, true);
                document.Replace("notas_cliente", txtNotasAltera.Text, false, true);               
                document.SaveToFile(@"c:\bootstraplocal\documentos_word\Fichacliente_id"+row["id"].ToString()+".docx", FileFormat.Docx);
                System.Diagnostics.Process.Start(@"c:\bootstraplocal\documentos_word\Fichacliente_id" + row["id"].ToString() + ".docx");
               


I need to replace notas_cliente with html. Any help,please?

Thank you

mariolopes
 
Posts: 9
Joined: Thu Oct 19, 2017 11:06 am

Thu Jul 25, 2019 7:08 pm

Found one way
Code: Select all
ocument document = new Document();             
                document.LoadFromFile(@"c:\bootstraplocal\documentos_word\Ficha do cliente.docx");

                TextSelection[] selections = document.FindAllString("Notas_cliente", true, true);
                foreach (TextSelection selection in selections)
                {
                    TextRange range = selection.GetAsOneRange();
                    Paragraph paragraph = range.OwnerParagraph;
                    int index = paragraph.ChildObjects.IndexOf(range);
                    paragraph.AppendHTML(row["notas"].ToString());
                   
                }

mariolopes
 
Posts: 9
Joined: Thu Oct 19, 2017 11:06 am

Fri Jul 26, 2019 1:16 am

Hello,

Thanks for your post.
Glad to hear that you found the solution. If you encounter any issue related to our products in the future, just feel free to contact us.
Wish you all the best!

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1261
Joined: Wed Apr 25, 2018 3:20 am

Return to Spire.Doc