Save Xml in an Excel cell value causes ComException

Posted by mas_oz2k1 on Stack Overflow See other posts from Stack Overflow or by mas_oz2k1
Published on 2010-03-16T03:13:13Z Indexed on 2010/03/16 17:01 UTC
Read the original article Hit count: 251

Filed under:
|
|
|

I am trying to save an object (Class1) as string in a cell value. My issue is that from time to time I have a ComException:

HRESULT: 0x8007000E (E_OUTOFMEMORY)

(It is kind of random but I have not identified any particular pattern yet) when I write the value into a cell. Any ideas will be welcome

For illustration purposes: Let Class1 be the class to be converted to an Xml string. (Notice that I removed the xml declaration at the start of the string to avoid having the preamble present- non printable character)
<Class1 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<ElementID> HL690375</ElementID>
</Class1>"

Class1 myClass = new Class1();
this class is converted to a string s. s= ConvertObjectToXmlString(myClass);
then s is assigned to a cell
Range r = Application.ActiveCell;
r.Value2 = s;

Note: (1) If the string is too big, I limit it to 32000 chars and split the string in chunks of 32000 chars and save the chunks in multiple cells.
(2) I do not to quote the string before adding to a cell. Do I need to? If so how it can be done?
(3) All object contents are English.
(4) C# code sample will be great but VB.net code is OK.

© Stack Overflow or respective owner

Related posts about excel

Related posts about automation