Hi I’m trying to create an automated validation checking program for microsoft word but I’m having trouble on validating and collecting text colours in word.
I’ve installed colordetectoractivites package but my bot is not able to get the text color, instead it selects and outputs the border colour.
Hi @Eogturtle ,
Could you let us know with an Example of what is the Input and the Expected End Output that you are trying to achieve ? We could try for a Background approach as well.
Thanks for replying! The input is a coloured text thats already present in the microsoft word document. The output that I’m trying to achieve is for the robot to give a text message with the corresponding colour of the text that is being read. In my use case, there will be 3 different texts with different colours. So I want my robot to read the texts of the different colours and output their corresponding colours in a message box.
Could you check with the below Workflow :
Word_GetWordsColor.zip (18.2 KB)
We are using Interop.Word
to get the words in the document and then get its font and color information. It uses Invoke Code
activity with the below code being used :
try
{
var wordApplication = new Microsoft.Office.Interop.Word.Application() { Visible = false };
var myDocument = wordApplication.Documents.Open(in_FilePath);
foreach( Microsoft.Office.Interop.Word.Range wordRange in myDocument.Words)
{
string wordText = wordRange.Text;
if(! String.IsNullOrWhiteSpace(wordText))
{
string fontColor = wordRange.Font.ColorIndex.ToString();
io_dt_WordColors.Rows.Add(wordText,fontColor);
}
}
wordApplication.Quit();
}
catch( Exception e)
{
Console.WriteLine(e.Source.ToString()+" "+e.Message.ToString());
}
We are collecting the words and color information in the form of a Datatable.
Hi,
SupermanPunch’s solution is definitely the more elegant way of however you could also automate the word advanced search using Ctrl + h hotkey and the format search, if you are in a situation solely within UiPath, maybe not exactly what you are looking for but It’s something I’ve done for validation of formats.
Thanks