C#读取Excel
利用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; //获取数组