예제 #1
0
 /// <summary>
 /// 循环获取Excel表格中所有列名
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnImportExcelFields_Click(object sender, EventArgs e)
 {
     try
     {
         //打开指定文件类型
         OpenFileDialog openFileDialog = new OpenFileDialog();
         openFileDialog.Filter           = "EXCEL文件(*.xls;*.xlsx)|*.xls;*.xlsx";
         openFileDialog.FilterIndex      = 1;
         openFileDialog.RestoreDirectory = true;
         openFileDialog.Title            = "导入Excel配件信息文件";
         if (openFileDialog.ShowDialog() == DialogResult.OK)
         {
             ExcelTable = CommonFuncCall.ImportExcelFile(openFileDialog.FileName);//获取Excel表格数据
         }
         else
         {
             return;
         }
         //获取所有Excel表格列名
         foreach (DataGridViewRow dgRow in dgMatchList.Rows)
         {
             CommonFuncCall.BindExcelHeadText((DataGridViewComboBoxCell)dgRow.Cells["ExcelField"], ExcelTable, ExcelFieldDefVal);
         }
     }catch (Exception ex)
     {
         MessageBoxEx.Show(ex.Message, "异常提示", MessageBoxButtons.OK, MessageBoxIcon.Question);
     }
 }