我正在开发一个 C# 应用程序,其中包含很多空的 DataGridViews。用户必须用 excel 中的复制/粘贴数据填充它们。我要做的是:
int i = 0;
string s = Clipboard.GetText();
// Separate lines
string[] lines = Regex.Split(s, "\r\n");
foreach (string line in lines)
{
// Separate each cell
string[] cells = line.Split('\t');
foreach (string cell in cells)
{
// If we selected as many cells as copied
if (dataGridView.SelectedCells.Count == (lines.Length-1)*(cells.Length))
{
dataGridView.SelectedCells[i].Value = cell;
i++;
}
}
}
问题是,如果我复制这样的内容(在 excel 上):
1 2 3
4 5 6
我的数据网格视图将如下所示:
6 4 2
5 3 1
我真的不知道该怎么做才能解决这个问题...在此先感谢