When I read from a Word Document and store the value in a paragraph variable, even if the words are written in Upper Case, they appear as Lower Case. Any idea why this is happening.
This is the line of code I have that I have used
para = CType(srcNode, Paragraph)
strVariable = para.Range.Text.Trim
Hello
Thanks for your request.
Unfortunately I was unable to reproduce the problem on my side.
Please attach simple project example and the input document. I will try to simulate the situation.
I have a word document that has the following lines
[[TEST FILE]]
BASE: ASSIGNED crm
As you can see, crm is in Lower case but when I see it in the document it is in Upper case.
And in the vb code that I have used to read the line is
For Each srcNode As Node In srcSection.Body
para = CType(srcNode, Paragraph)
strParagraphText = para.Range.Text.Trim
Next
Hi
Thanks for additional information.
MS Word provides a formatting option to show text as uppercase, even when it is not. Aspose.Words also do it.
You apply this option by choosing the All Caps check box on the Font dialog box.
If you want to get all the text with capital letters, you have to go through all the text elements, convert them to uppercase and remove the option Font.AllCaps. Best for this using DocumentVisitor.
public class DocVisitor: DocumentVisitor
{
public override VisitorAction VisitRun(Run run)
{
if (run.Font.AllCaps)
{
run.Text = run.Text.ToUpper();
run.Font.AllCaps = false;
}
// Let the visitor continue visiting other nodes.
return VisitorAction.Continue;
}
}
Hi,
Thanks for additional information.
As I’ve said, for the text there is an opportunity to set the parameter Font.AllCaps = true;. Then, even the text of a writing with a lowercase letter will be seen as uppercase.
In your example the word “crm” is such a case. In MS Word right-click on the word “CRM”, then select the Font you’ll see that you have checked on the option All caps.
``
Try to disable this option and you will see the real state of the text as it was actually written.
The same thing is happening in your cycle when you read the text of the paragraph, the word “CRM” is actualy written in lowercase. But if you want what you read, match what you see is what you need to convert text as I suggested earlier.
Hi
Thanks for your request. Actually, Aspose.Words uses DocumentVisitor to retrieve text from document. So, if you implement your own DocumentVisitor to get text from document, there will be no performance impact. For instance, you can implement DocumentVisitor like one provided in this article: https://reference.aspose.com/words/net/aspose.words/documentvisitor/
Best regards,
Thanks for that reply.
It really helped me solve the issue.
However I would like to know if there is any way to check for the ALL CAPS option in a string.
As in, if I say
Dim _StrText as String _strText=_para.Range.Text
is there anyway to check if the text has the ALL CAPS property checked.