PasteFromExcelData (c#)

 string ClipboardData { get { IDataObject iData = Clipboard.GetDataObject(); if (iData == null) return ""; if (iData.GetDataPresent(DataFormats.Text)) return (string)iData.GetData(DataFormats.Text); return ""; } set { Clipboard.SetDataObject(value); } }

private void PasteFromExcelData()
{
string[] data = ClipboardData.Split('\n');
if (data.Length < 1) return;
foreach (string row in data)
{
AddRow(row);
}
}

void AddRow(string data)
{
if (data == string.Empty) return;
string[] rowData = data.Split(new char[] { '\r', '\x09' });
DataTable tbl = this.northwndDataSet1.Table_1;
DataRow newRow = tbl.NewRow();
for (int i = 0; i < rowData.Length-1; i++)
{
newRow[i+1] = rowData[i].ToString();
}
tbl.Rows.Add(newRow);
}

Yorumlar