/// <summary> /// 导入EXCEL表格 /// </summary> private void LoadExcel() { ClsImportExcel importExcel = new ClsImportExcel(); LoadDataTable(importExcel.loadExcelDataTalbe);//将导入的表赋值给显示表格的dataGridView strTableName = importExcel.strCurrentTableName; //还得选择哪个是数量 loadPrintedQtytoComboBox(); }
private void btnLoadExcel_Click(object sender, EventArgs e) { ClsImportExcel importExcel = new ClsImportExcel(); dataGridView1.DataSource = importExcel.loadExcelDataTalbe;//将导入的表赋值给显示表格的dataGridView strCurrentTableName = importExcel.strCurrentTableName; //将导入的表作为最新的数据更新到listView . dataGridViewChangedCell(); //还得选择哪个是数量 loadPrintedQtytoComboBox(); /** //选择是哪个档口 FrmSCAndShop myFrmSCAndShop = new FrmSCAndShop(); if (myFrmSCAndShop.ShowDialog() != DialogResult.OK)//只要判断这个就可以了。 { MessageBox.Show("请输入单号(名)和档口号(名),以方便以后查看"); return; } //选择文件 string strFile; openFileDialog1.Filter = "Excel97-2003 Excel 2007(*.xls *.xlsx)|*.xls;*.xlsx|All files (*.*)|*.*"; openFileDialog1.FilterIndex = 1; if (openFileDialog1.ShowDialog() == DialogResult.OK) { strFile = openFileDialog1.FileName; } else { MessageBox.Show("请选择文件"); return; } // 首先判断这个excel表格有几页,如果只有一页就直接导入,如果不止一页就让用户选择 string[] strSheetNames = GetExcelSheetNames(strFile); DataTable loadExcelDataTalbe;//就是将excle 导入这个数据中, if (strSheetNames.Length == 1) { //读入表 loadExcelDataTalbe = GetExcelToDataSet(strFile, false, strSheetNames[0]); } else { //选择读入那个表 FrmChooseExcelSheet frm = new FrmChooseExcelSheet(strSheetNames); frm.ShowDialog(); loadExcelDataTalbe = GetExcelToDataSet(strFile, false, FrmChooseExcelSheet.strSheetName); } dataGridView1.DataSource = loadExcelDataTalbe;//将导入的表赋值给显示表格的dataGridView //将导入的表作为最新的数据更新到listView . dataGridViewChangedCell(); //将导入的表导入到数据库, ClsDataBase myClsDataBase = new ClsDataBase(); strCurrentTableName = myClsDataBase.loadExcel(FrmSCAndShop.strSC, FrmSCAndShop.strShop, Path.GetFileName(strFile), loadExcelDataTalbe); * */ }