Blo*_*owi 7 c# excel clipboard datagridview copy-paste
我正在开发一个包含大量DataGridViews的C#应用程序.用户必须使用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++;
}
}
}
Run Code Online (Sandbox Code Playgroud)
问题是如果我复制这样的东西(在excel上):
1 2 3
4 5 6
Run Code Online (Sandbox Code Playgroud)
我的datagridview看起来像:
6 4 2
5 3 1
Run Code Online (Sandbox Code Playgroud)
我真的不知道该怎么做才能解决这个问题...提前谢谢
代替
dataGridView.SelectedCells[i].Value = cell;
和
dataGridView.SelectedCells[(dataGridView.SelectedCells.Count-1) - i].Value = cell;
| 归档时间: |
|
| 查看次数: |
1237 次 |
| 最近记录: |