强制从NPOI到microsoft interop,我必须执行在工作簿中查找某个工作表的任务,然后遍历它的每一行。
在NPOI中,它只是workbook.GetSheet(sheetName);
。在microsoft interop中,这相当于什么?
答案 0 :(得分:24)
使用workbook.Sheets[sheetName];
完成工作示例:
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();
}
}