Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application(); Workbooks wbks = app.Workbooks; object missing = System.Reflection.Missing.Value; string excelPath = System.Windows.Forms.Application.StartupPath + @"\template\source.xlsx"; _Workbook _wbk = wbks.Open(excelPath, missing, true, missing, missing, missing, missing, missing, missing, true, missing, missing, missing, missing, missing); app.Visible = true; Sheets shs = _wbk.Sheets; _Worksheet _wsh = (_Worksheet)shs.get_Item(1); Range rng1 = _wsh.Cells.get_Range("A2", "F29"); object[,] arrayItem = (object[,])rng1.Value2; int unit_id = 0; object[] lastLine = new object[6]; for (int i = 1; i <= arrayItem.GetLength(0); i++) { //每一行进行循环 object[] tempOriginal = new object[6]; for (int j = 1; j <= arrayItem.GetLength(1); j++) tempOriginal[j - 1] = arrayItem[i, j];//取值 doSomething(); } _wbk.Close(); wbks.Close(); wbks = null; app.Quit(); app = null;
标签:读取,missing,C#,app,object,Excel,Application,true From: https://www.cnblogs.com/adamgq/p/16902207.html