public static string DataTableToString(DataTable dt)
{
string dtstring = "";
for (int i = 0; i < dt.Columns.Count; i++)
{
dtstring =dtstring+ dt.Columns[i].ColumnName + "/t";
}
dtstring =dtstring+ "/r/n";
for (int i = 0; i < dt.Rows.Count; i++)
{
for (int j = 0; j < dt.Columns.Count; j++)
{
dtstring =dtstring+ dt.Rows[i][j] + "/t";
}
dtstring = dtstring + "/r/n";
}
return dtstring;
}
string strTemp = DataTableToString(tt);
if (strTemp.Equals("")) //判断是否为空
return;
Clipboard.Clear();//清除原有剪切板中内容
Clipboard.SetText(strTemp);//将文字添加到剪切板中,还添加Object类型数据