导入excle读取表头添加到对应的源字段列表里

    void inputexcle()
        {

            string msg = string.Empty;
            try
            {
                var ofd = new OpenFileDialog()
                {

                    Filter = "Microsoft Office Excel 工作簿(*.xls)|*.xls",
                    Multiselect = false
                };
                if (ofd.ShowDialog() == DialogResult.Cancel) return;
                this.btintable.Text = ofd.FileName;
                dtexcle.Clear();
                dtexclebk.Clear();
                dtexcle =dtexclebk= BinData.InputExcel(ofd.FileName, ref msg);
                this.repositoryItemComboBox1.Items.Clear();
                foreach (DataColumn cl in dtexcle.Columns)
                {
                    this.repositoryItemComboBox1.Items.AddRange(new object[] {
          cl.ColumnName.ToString(),});
                }
                this.repositoryItemComboBox1.Items.AddRange(new object[] {
          "",});
            }
            catch
            {
                MessageBox.Show(msg);
            }

        }

repositoryItemComboBox1是gridview中一个combox控件。

原文地址:https://www.cnblogs.com/bantongshui/p/3170000.html