读取表头作为目标表字段gridview

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

                    Filter = "Microsoft Office Excel 工作簿(*.xls)|*.xls",
                    Multiselect = false
                };
                if (ofd.ShowDialog() == DialogResult.Cancel) return;

                DataTable dt = BinData.InputExcel(ofd.FileName, ref msg);
                DataTable input = new DataTable();
                input.Columns.Add("input", typeof(string));
                input.Columns.Add("sysfileds", typeof(string));
                foreach (DataColumn cl in dt.Columns)
                {
                    DataRow dr = input.NewRow();
                    dr["input"] = cl.ColumnName.ToString();
                    input.Rows.Add(dr);
                }
                this.gridControl1.DataSource = input;

            }
            catch
            {
                MessageBox.Show(msg);
            }
        }

 

posted @ 2013-06-06 22:41  永远的菜鸟@me  阅读(220)  评论(0编辑  收藏  举报