First, open Excel
(A) Method a: operation using Microsoft.Office.Interop.Excel.dll
First, we need to reference a dll
1 using Excel = Microsoft.Office.Interop.Excel;
Then directly execute the following code:
1 string excelName = "";//你的excel文件的位置 2 string sheetName = "";//你的sheet的名字 3 object missing = Type.Missing; 4 Excel.Application excel = new Excel.Application(); 5 Excel.Workbook book = excel.Workbooks.Open(excelName, missing, 6 missing, missing, missing, missing, missing, missing, missing, 7 missing, missing, missing, missing, missing, missing); 8 Excel.Worksheet sheet = book.Worksheets[sheetName]; 9 excel.Visible = true;
(B) Method II: Direct calling terminal is opened
. 1 String SS = "" ; // you excel path 2 the System.Diagnostics.Process.Start (SS);
Second, open Excel and navigate to a sheet
1 string excelName = "";//你的excel文件的位置 2 string sheetName = "";//你的sheet的名字 3 object missing = Type.Missing; 4 Excel.Application excel = new Excel.Application(); 5 Excel.Workbook book = excel.Workbooks.Open(excelName, missing, 6 missing, missing, missing, missing, missing, missing, missing, 7 missing, missing, missing, missing, missing, missing); 8 Excel.Worksheet sheet = book.Worksheets[sheetName]; 9 sheet.Activate(); 10 excel.Visible = true;
Third, open Excel and locate a cell
. 1 String excelName = "" ; // location of your excel file 2 String sheetName = "" ; // your name sheet . 3 String strStart = " AlOO " ; // the starting cell . 4 String strEnd = " B200 " ; // end cell . 5 Object Missing = Type.Missing; . 6 the Excel.Application Excel = new new the Excel.Application (); . 7 Excel.Workbook Book = excel.Workbooks.Open (excelName, Missing, 8 missing, missing, missing, missing, missing, missing, missing, 9 missing, missing, missing, missing, missing, missing); 10 Excel.Worksheet sheet = book.Worksheets[sheetName]; 11 excel.Application.Goto(sheet.Range[strStart, strEnd], true); 12 excel.Visible = true;
II and III also need to add the dll excel