How to get text from shape?

The code @whitestar 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