Windows.DataObject.GetData("String")在Excel中用于大量行时,出现内存不足异常 [英] Out of memory exception when Windows.DataObject.GetData("String") for large number of rows in excel
问题描述
我有一个粘贴事件处理程序,当用户从excel复制数据并将其粘贴到我们的应用程序中时会触发该事件.
I have a pasting event handler which is fired when user copies data from excel and pastes into our application.
我们获得了传递给事件处理程序的DataObjectPastingEventArgs对象.当剪贴板上有大量数据时,当我们在 行:
We get a DataObjectPastingEventArgs object passed to the event handler. When there is a large amount of data on the clipboard, we get an out of memory exception when we at the line:
string inputString = d ataObject.GetData( ( )).ToString();
string inputString = dataObject.GetData(typeof(string)).ToString();
是否有一种方法可以从DataObject中流式传输数据,以便我们不会出现此异常?
Is there a way to stream data from the DataObject so that we don't get this exception?
推荐答案
您可以尝试使用Clipboard.GetText方法:
You could try to use the Clipboard.GetText method:
if (Clipboard.ContainsText(TextDataFormat.CommaSeparatedValue))
{
string text = Clipboard.GetText(TextDataFormat.CommaSeparatedValue);
}
IDataObject.GetData(Type)方法是从.NET应用程序中的剪贴板访问数据的首选方法,该应用程序的目标版本比.NET Framework 2早.
The IDataObject.GetData(Type) method is the preferred way of accessing data from the Clipboard in .NET applications that target an earlier version than .NET Framework 2.
请参阅以下链接以获取更多信息:
Please refer to the following link for more information:
如何:从剪贴板中检索数据: http://msdn.microsoft.com/zh-CN/library/c2thcsx4.aspx
How to: Retrieve Data from the Clipboard: http://msdn.microsoft.com/en-us/library/c2thcsx4.aspx
这篇关于Windows.DataObject.GetData("String")在Excel中用于大量行时,出现内存不足异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!