How to read cell using VBNet invoke code

I would like to use invoke code to read individual cell values from an excel worksheet. Has anyone done this?

use microsoft interop excel

I’m using Microsoft.Interop.Excel but have only figured out to write data - not read it. Can you share the code used to read individual cells?

Why do you want to do it in Invoke Code instead of using the simple activity Read Cell?

I’m currently using the read cell activities but have them reading numerous cells and would like to increase performance and readability by consolidating the code into one activity.

That kind of consolidation doesn’t actually increase readabilitiy. Invoke Code is more difficult for someone else to interpret, and doesn’t provide useful error messages. You’re much better off using actual Activities. The Workbook activities are faster than the Excel Application Scope activities, if performance is an issue.

The other way to go would be to read the entire spreadsheet into a datatable and then get the values from the datatable.

Thanks for your input. Without going into too much detail, this specific spot in the script is inside a loop and is doing much more than just reading cells. The loop is currently inside an invoke code and has to hop out of the it just to read a bunch of cells to validate a template structure for thousands of files. So, in that regard, both readability and performance are pretty drastically affected.

The loop is already writing data via Microsoft.Interop.Excel. I would just like some information as to how I can read the cells via this method.