日期:2014-05-17  浏览次数:20454 次

100分求解决:datagridview打开Excel报错:名为“ClampVal”的列已属于此 DataTable。
在网上copy了份datagridview打开Excel的代码,打开Excel报错:名为“ClampVal”的列已属于此 DataTable。
Columns 不允许列名相同,但我又不能变更Excel数据.ClampVal列我也没显示在datagridview控件上,请问下有什么解决办法可以正常打开excel?


 if (openFileDialog1.ShowDialog() == DialogResult.OK) //OK表示按下了“打开”
            {

                string s = null;
                DataTable table = new DataTable("auto");

                DataRow row = null;
                String[] split = null;

                using (StreamReader sr = new StreamReader(openFileDialog1.FileName, UnicodeEncoding.GetEncoding("GB2312")))
                {
                    s = sr.ReadLine();
                    split = s.Split(',');
                    int i = 0;
            
                    foreach (String colname in split)
                    {
                        //名为“ClampVal”的列已属于此 DataTable。
                        table.Columns.Add(colname, System.Type.GetType("System.String"));
                        
                        i++;
                    }

                    int j = 0;
                    while (sr.Peek() > -1)
                    {
                        s = sr.ReadLine();

                        j = 0;
                &