C# 剪贴板帮助
我正在将 Excel 文件的内容复制到我编写的程序中的剪贴板上。然后我可以使用内存中的数据,而不是不断地与 Excel“聊天”。
当我完成数据处理后,我调用了一个清理方法,该方法首先调用 Clipboard.Clear(),然后关闭所有 Excel 工作表/工作簿/应用程序等。
问题是,即使我在关闭 Excel 工作表之前清除了剪贴板,我收到一个弹出窗口,仍然显示剪贴板上有大量数据。有人知道为什么吗?
谢谢,
达伦。
I am copying the contents of an Excel file onto the Clipboard within a program I have written. I can then use that data in memory rather than 'chatting' constantly with Excel.
When I have finished with the data, I cal a cleanup method that calls Clipboard.Clear() first and then closes all Excel sheets/workbooks/apps, etc.
The problem is, even though I clear the Clipboard prior to closing the Excel sheets, I get a pop up window still saying there is substantial amount of data on the clipboard. Anybody know why?
Thanks,
Darren.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
不确定为什么会发生这种情况,但您是否尝试设置
_Application.DisplayAlerts = false;
(MSDN) 在关闭工作表之前查看是否会阻止警告消息?Not sure why that happens, but have you tried setting
_Application.DisplayAlerts = false;
(MSDN) before you close the sheets to see if that prevents the warning message?您可以尝试设置 Excel
CutCopyMode
property 取消当前的复制信息:另一个想法是将剪贴板设置为 String.Empty ,这样复制的数据量就足够小,从而绕过警告弹出窗口。这可能必须从 Excel 工作表完成,而不是常规剪贴板(即从 Excel 中的活动工作表复制单元格)。
You could try setting the Excel
CutCopyMode
property to cancel the current copy information:Another thought is to set the clipboard to
String.Empty
so the amount of data copied is small enough that it bypasses the warning popup. This may have to be done from the Excel sheet, not the regular clipboard (i.e., copy a cell from the active sheet in Excel).也许你可以使用
Application.CutCopyMode = false;
http://msdn.microsoft.com/en-us/library/ff839532.aspx
Perhaps you could use
Application.CutCopyMode = false;
http://msdn.microsoft.com/en-us/library/ff839532.aspx
最后,尝试在剪贴板中复制一个空字符串并保留它,然后 Excel 可能不会给出任何警告。但使用 Excel API 复制剪贴板中的空字符串。
Well at the end, try copying an empty string in clipboard and leave it, then Excel may not give any warning. But use Excel API to copy empty string in clipboard.