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 Mar 11, 2021 10:49 pm
problem.png
I use replace text and the text comes out that way
solution.png
i need it that way
Login to view the files attached to this post.
-
josefreyle
-
- Posts: 5
- Joined: Tue Sep 01, 2020 3:11 pm
Fri Mar 12, 2021 3:40 am
Hello,
Thanks for your inquiry.
Please refer to the following code to replace text with HTML-style string. Feel free to contact us if you have further questions.
- Code: Select all
Document doc = new Document("input.docx");
string str = "replace text";
string html = "Your html string";
Document docHtml = new Document();
docHtml.AddSection().AddParagraph().AppendHTML(html);
IDocument replaceDoc = docHtml as IDocument;
doc.Replace(str, replaceDoc, false, false);
doc.SaveToFile("result.docx", FileFormat.Docx);
Sincerely,
Rachel
E-iceblue support team
-
rachel.lei
-
- Posts: 1571
- Joined: Tue Jul 09, 2019 2:22 am
Tue Mar 16, 2021 4:33 pm
and this is possible?
Sin título.png
Login to view the files attached to this post.
-
josefreyle
-
- Posts: 5
- Joined: Tue Sep 01, 2020 3:11 pm
Wed Mar 17, 2021 1:47 am
Hello,
Thanks for your reply.
You want to replace text with HTML tables, right? This is also possible, below is my test code. You can give it a try.
- Code: Select all
Document doc = new Document("input.docx");
string str = "replace text";
string html = "<table><tr><th>Product</th><th>Month</th><th>Sales</th></tr><tr><td>Spire.Doc</td><td>Jun</td><td>3000</td></tr><tr><td>Spire.Doc</td><td>Oct</td><td>3000</td></tr><tr><td>Spire.Doc</td><td>Dec</td><td>3000</td></tr></table>";
Document docHtml = new Document();
docHtml.AddSection().AddParagraph().AppendHTML(html);
IDocument replaceDoc = docHtml as IDocument;
doc.Replace(str, replaceDoc, false, false);
doc.SaveToFile("result.docx", FileFormat.Docx);
Sincerely,
Rachel
E-iceblue support team
-
rachel.lei
-
- Posts: 1571
- Joined: Tue Jul 09, 2019 2:22 am
Tue Mar 23, 2021 9:41 am
Hello,
Hope you are doing well.
Did my code work for you? Looking forward to your feedback!
Sincerely,
Rachel
E-iceblue support team
-
rachel.lei
-
- Posts: 1571
- Joined: Tue Jul 09, 2019 2:22 am