C#讀取Excel
阿新 • • 發佈:2018-10-25
obj ati 規律 ksh item 數據 lis path col
利用C#讀取Excel中的數據
由於特殊橋的腳手架形狀並不完全規律,導致腳手桿的間距不統一無法順利循環,所以決定利用Excel導入間距數據再進行布設
1 string path = @"D:\Text.xls"; //Excel目錄, 2 3 //加載Excel 4 Excel.Application app = new Excel.Application(); //獲取權限 5 Excel.Workbooks workbooks = app.Workbooks; 6 Excel.Workbook workbook = workbooks.Add(path);7 8 9 //獲取sheet 10 Excel.Sheets sheet = workbook.Sheets; 11 12 Excel.Worksheet worksheet = (Excel.Worksheet)sheet.get_Item(1);//獲取sheet (1)為第一個sheet 13 14 double usedRows = app.WorksheetFunction.CountA(worksheet.Columns[3]); //第3列的行數 15 16 string num = usedRows.ToString();17 18 object[,] twoDoubleList = worksheet.Range["A1:C" + num].Value2; //獲取數組
C#讀取Excel