Being forced from NPOI to microsoft interop, I have to perform a task of finding a certain worksheet in workbook, and then iterate through every row of it.
In NPOI it would be simply workbook.GetSheet(sheetName);
. What would be the equivalent for this in microsoft interop?
Application. ActiveWorkbook. Sheets[1]). Select();
Right-click the text box to select it, press Ctrl+K to launch the Insert Hyperlink dialog box, select Place in This Document (under the Link to menu), scroll down to Defined Names, select TOC, and press OK. These actions will create a clickable button that will return you to your table of contents.
Use workbook.Sheets[sheetName];
Complete working example:
using Microsoft.Office.Interop.Excel;
class Program
{
static void Main(string[] args)
{
var excelApplication = new Application();
excelApplication.Visible = true;
excelApplication.SheetsInNewWorkbook = 3;
var workbook = excelApplication.Workbooks.Add();
var worksheet = workbook.Sheets["Sheet2"]; //<--- desired method
worksheet.Activate();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With