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.

Wed Jun 22, 2016 1:27 am

Hello, I want to export a word document like the attachment file(initial.jpg). And then I get the DataTable value to replace it,and the result like the attachment file(result.jpg). How can I do that?
I use code like this:
TextSelection textProject = document.FindString("项目名称:", false, true);
but in the word document, how can I deal with the underline attribute? Thank you

dim_best
 
Posts: 12
Joined: Wed Jun 08, 2016 6:17 am

Wed Jun 22, 2016 2:45 am

Hi,

Thanks for your posting.
Please try the following code.
Code: Select all
Document document = new Document();
            document.LoadFromFile(input);

            TextSelection selection1 = document.FindString("项目名称:", false, true);
            //get the text range of selection1
            TextRange range = selection1.GetAsOneRange();
            //get the paragraph of selection1
            Paragraph paragraph= selection1.GetAsOneRange().OwnerParagraph;
            //get the index of text range in paragraph
            int index = paragraph.ChildObjects.IndexOf(range);
            //get the text range will be added text
            TextRange toRange = paragraph.ChildObjects[index + 1] as TextRange;
            toRange.Text = "Test Project";

            document.SaveToFile(result, FileFormat.Docx);


Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Fri Jun 24, 2016 8:08 am

Hi,

Did the above solution help you?
Thanks for your feedback in advance.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.Doc