How to get text from shape?

Hello O Great Helpers,
How can i extract text from specific shape?
Exp.xlsx (9.0 KB)
Thanks alot

Try this vb code ?

1 Like

The code @phyomt refer to should work fine if you use it inside an Invoke Code activity and change “AlternativeText” to “TextFrame.Characters().Text”.

image

If you prefer C# instead of VB.NET:

string excelFile = Path.Combine(Directory.GetCurrentDirectory(), @"Data\Exp.xlsx");

Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();

Microsoft.Office.Interop.Excel.Workbook wb = excel.Workbooks.Open(Filename: excelFile, ReadOnly: true);
Microsoft.Office.Interop.Excel.Worksheet sheet = wb.Sheets["Sheet1"] as Microsoft.Office.Interop.Excel.Worksheet; 

// To read a specific shape
Microsoft.Office.Interop.Excel.Shape foundShape = sheet.Shapes.Item("Rectangle 36");
System.Windows.MessageBox.Show(foundShape.Name + ": " + foundShape.TextFrame.Characters().Text);

wb.Close(SaveChanges: false);
excel.Quit();

It might be tricky to get Invoke Code to work with Interop.Excel. See this post on how to get it to work: HOWTO: Use MS Office COM interop with UiPath

2 Likes

Thanks for the reply but do i need to configure trust center in excel to be able to invoke code? truly sorry for my naivety and late reply.

Thanks alot for helping sir

You are welcome!

No, you don’t need to configure Trust Center to get Invoke Code to work. Invoke Code executes real code (i.e. not a macro/VBA).

1 Like

Thanks

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.