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 26, 2024 10:03 pm
Is there any way to get the range of underlined text from each line?
Below is a sample of a failed attempt I have tried:
foreach (TextRange textRange in paragraph)
{
if (textRange.CharacterFormat.UnderlineStyle != UnderlineStyle.None)
{
Console.WriteLine("Underlined text: " + textRange.ToString());
}
}
Thank you!
-

bcamp011
-
- Posts: 6
- Joined: Wed Feb 07, 2024 9:10 pm
Wed Mar 27, 2024 2:42 am
Hello,
Thanks for your inquiry.
Please refer to the code below to obtain the text with an underline. If it still doesn't work, please provide us with your input file and we will further investigate. You can attach it here or send it to us via email (
[email protected]). Thank you in advance.
Sincerely,
William
E-iceblue support team
-


William.Zhang
-
- Posts: 758
- Joined: Mon Dec 27, 2021 2:23 am
Wed Mar 27, 2024 2:56 am
I'm sorry, I don't see the code posted.
-

bcamp011
-
- Posts: 6
- Joined: Wed Feb 07, 2024 9:10 pm
Wed Mar 27, 2024 3:16 am
Hello,
Thanks for your reply.
Sorry, I forgot to attach the code.
- Code: Select all
Document document = new Document();
document.LoadFromFile("test.docx");
foreach(Spire.Doc.Section section in document.Sections)
{
Spire.Doc.Collections.DocumentObjectCollection childObjects = section.Body.ChildObjects;
foreach (DocumentObject documentObj in childObjects)
{
if(documentObj is Paragraph)
{
Paragraph paragraph = (Paragraph)documentObj;
foreach (DocumentObject documentObject in paragraph.ChildObjects)
{
if (documentObject is TextRange)
{
TextRange textRange = (TextRange)documentObject;
if (textRange.CharacterFormat.UnderlineStyle != UnderlineStyle.None)
{
string text = textRange.Text;
}
}
}
}
}
}
Sincerely,
William
E-iceblue support team
-


William.Zhang
-
- Posts: 758
- Joined: Mon Dec 27, 2021 2:23 am