在 ClipboardPasting 中获取,然后添加行
- fpSpread1.ClipboardPasting += FpSpread1_ClipboardPasting;
- }
- private void FpSpread1_ClipboardPasting(object sender, ClipboardPastingEventArgs e)
- {
- IDataObject data = Clipboard.GetDataObject();
- string clipText = string.Empty;
- if (data.GetDataPresent(DataFormats.StringFormat))
- clipText = (string)data.GetData(DataFormats.StringFormat);
- else if (data.GetDataPresent(DataFormats.UnicodeText))
- clipText = (string)data.GetData(DataFormats.UnicodeText);
- else if (data.GetDataPresent(DataFormats.OemText))
- clipText = (string)data.GetData(DataFormats.OemText);
- else if (data.GetDataPresent(DataFormats.Text))
- clipText = (string)data.GetData(DataFormats.Text);
- if (clipText != string.Empty)
- {
- string[] rows = clipText.Split(new string[] { "\r\n" }, StringSplitOptions.None);
- int rowCount = rows.Length - 1;
- if (rowCount > 0)
- {
- var actRow = fpSpread1.ActiveSheet.ActiveRow.Index;
- if (actRow + rowCount > fpSpread1.ActiveSheet.RowCount)
- {
- fpSpread1.ActiveSheet.AddRows(fpSpread1.ActiveSheet.RowCount, actRow + rowCount - fpSpread1.ActiveSheet.RowCount);
- }
- }
- }
- }
复制代码 |