使用剪贴板时出现 Spreadsheetgear 错误
在我的应用程序中,我使用电子表格齿轮来处理 Excel 文件。我使用以下代码:
//move incorrect to aux
incorrectLine.Select(); //select the line to be moved
wbkView.Cut();
auxLine.Select();
wbkView.Paste();
//move correct to incorrect
correctLine.Select(); //select the line to be moved
wbkView.Cut();
incorrectLine.Select();
wbkView.Paste();
//move aux to correct
auxLine.Select(); //select the line to be moved
wbkView.Cut();
correctLine.Select();
wbkView.Paste();
我不时收到以下错误:
Requested Clipboard operation did not succeed.
使用 StrackTrace:
at System.Windows.Forms.Clipboard.ThrowIfFailed(Int32 hr)
和 ErrorCode = -2147221040
据我了解,如果剪贴板被其他进程使用,则会出现问题,所以我想知道是否存在另一种模式可以在不使用剪贴板的情况下从 Excel 文件切换两行。
In my application I use spreadsheetgear to work with Excel files. I use the following code:
//move incorrect to aux
incorrectLine.Select(); //select the line to be moved
wbkView.Cut();
auxLine.Select();
wbkView.Paste();
//move correct to incorrect
correctLine.Select(); //select the line to be moved
wbkView.Cut();
incorrectLine.Select();
wbkView.Paste();
//move aux to correct
auxLine.Select(); //select the line to be moved
wbkView.Cut();
correctLine.Select();
wbkView.Paste();
I receive from time to time the following error:
Requested Clipboard operation did not succeed.
with the StrackTrace:
at System.Windows.Forms.Clipboard.ThrowIfFailed(Int32 hr)
and ErrorCode = -2147221040
From what I understand there is a problem if the clipboard is used by other process so I want to know if exists another mode to switch two lines from an Excel file without using the clipboard.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您也许可以使用 IRange.Copy(...) 方法而不是 WorkbookView.Cut/Paste。此方法在 SpreadsheetGear 内部执行复制例程,无需使用 Windows 剪贴板,因此可以避免出现类似您在此处看到的问题。另外,您不需要所有这些 Select 方法调用来在工作表中导航。
明显的问题是,这是一个复制例程,而不是剪切例程,它们的行为在很多方面都不同:
将它们放在一起,您的代码可能如下所示:
You might be able to use the IRange.Copy(...) method instead of WorkbookView.Cut/Paste. This method performs a copy routine internally within SpreadsheetGear, without the use of the Windows Clipboard, so would avoid any problems like the one you are seeing here. Plus, you wouldn’t need all those Select method calls to navigate around the worksheet.
The obvious problem is that this is a copy routine and not a cut routine, which behave different from one another in a variety of ways:
Putting it all together, your code might look like the following: