private void copydata(stringdata1) {string clipboardText = Clipboard.GetText(); //获取剪贴板中的内容
if (data1.Trim().Length < 1) { return; }try{int colnum = 0;int rownum = 0;for (int i = 0; i < clipboardText.Length; i++)
{if (clipboardText.Substring(i, 1).Equals("\t"))
{
colnum++;
}if (clipboardText.Substring(i, 1).Equals("\n"))
{
rownum++;
}
}//粘贴板上的数据来源于EXCEL时,每行末尾都有\n,来源于DataGridView是,最后一行末尾没有\n
if (clipboardText.Substring(clipboardText.Length - 1, 1) == "\n")
{
rownum--;
}
colnum= colnum / (rownum + 1);object[,] data; //定义object类型的二维数组
data = new object[rownum + 1, colnum + 1]; //根据剪贴板的行列数实例化数组
string rowStr = "";//对数组各元素赋值
for (int i = 0; i <