views:

61

answers:

1

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.

A: 

It may be that your created string (s) contains 'illegal' characters at times... like a $ which Excel is trying to convert into another cell location... It may not be EXACTLY a $ but you get the idea.

tobrien
Do you know where I can find the list of 'illegal' characters?, so that I can identify them in my code.Can quoting the string before writing the value into the cell is a workaround?
mas_oz2k1
Check Excel's help file. No you cannot quote.
AMissico
I placed illegal within a quote since nothing is particularly illegal, per se, its just that some string of chars may be misinterpreted (i.e. $A101, or some XL function name) You could place a TRY CATCH around the code that empties the data into the cell but you'll likely get back an error that is correct but not meaningful at first. It may be that you can FORCE the format of the target cell to only accept STRINGs and thereby 'turn off' the XL parser.
tobrien
Let me check and I will get back to you
mas_oz2k1