US preadsheetgear错误时使用剪贴板 [英] Spreadsheetgear error when uses clipboard

查看:189
本文介绍了US preadsheetgear错误时使用剪贴板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序将S preadsheetgear与Excel文件的工作。我用下面的code:

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. 

与StrackTrace:

with the StrackTrace:

at System.Windows.Forms.Clipboard.ThrowIfFailed(Int32 hr)

错误code = -2147221040

据我了解还有如果剪贴板由其他进程,所以我想知道是否存在另一种模式,在不使用剪贴板切换从Excel文件中的两行的问题。

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.

推荐答案

您可能能够使用IRange.Copy(...)方法,而不是WorkbookView.Cut /粘贴。此方法执行内部指定S preadsheetGear一个拷贝过程,而无需使用Windows剪贴板中,这样就可以避免像你在这里看到一个什么问题。另外,你不会需要所有这些选择的方法调用浏览工作表中各地。

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:

  • 复制显然离开源范围不变;斩将删除源范围值和格式。你可以调用IRange.Copy后解决此通过清除通过IRange.Clear(来源范围)()。
  • 更巧妙的是,如果你的源范围包含公式或指定范围,这些公式中的引用,并使用切当副本,而不是也被命名范围将有可能被固定在不同的方式。没有太多可以做这个,因为这仅仅是Excel中的工作方式,以及S preadsheetGear如下这些东西Excel中的领先地位。当然,如果你的源范围只是没有命名区域简单的值,这是没有问题的。

全部放在一起,你的code可能如下所示:

Putting it all together, your code might look like the following:

// move incorrect to aux
incorrectLine.Copy(auxLine);
incorrectLine.Clear();

// move correct to incorrect
correctLine.Copy(incorrectLine);
correctLine.Clear();

// move aux to correct
auxLine.Copy(correctLine);
auxLine.Clear();

这篇关于US preadsheetgear错误时使用剪贴板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆