wpf/sliverlight EXCEL数据复制粘贴到dateagrid中

来源:互联网 发布:扒皮淘宝优菲猫 编辑:程序博客网 时间:2024/04/28 19:20

在datagrid的keydown时间中处理出具  

  private void grid_KeyDown(object sender, KeyEventArgs e)

        {

    string str = System.Windows.Clipboard.GetText();//获取剪切板数据
            //  数据载体 data = new 数据载体();
            if (string.IsNullOrEmpty(str.Trim()) == false)
            {
                string[] rows = str.Split('\n');//分行
                int colIndex = 0;
                int r = 0;
                int c = 0;
                //循环行
                foreach (var item in rows)
                {
                    string[] cols = item.Split('\t');//分列
                    if (!string.IsNullOrEmpty(item))
                    {
                        if (colIndex + c == 0)
                        {


                            //data.XXX=colStr
                        }
                        else if (colIndex + c == 1)
                        {
                            //ata.YYY=colStr
                        }
                    }
                }
            }
            //  list.Add(data);
            //绑定datagrid


        }
原创粉丝点击