Interop Error writing strings into Excel

C

Code Deaf

I'm getting an error in my c# app when trying to insert a block of text from
a string array into an Excel cell.

The line of code which reads the string goes like this:

FSInfo[2] = FSPage.Substring(pos3 + 148, k - pos3 - 147);

This line assigns a substring of length (k - pos3 - 147) to a string array
FSInfo[], starting at position pos3 + 148.

The line which generates the error is the set_Value line in this block,
which tries to write the substring into Excel:

public bool InsertDataAt(string start, string[,] data)
{
ExcelCOM.Range theCells = MyWorksheet.get_Range(start,
typeMissing);
theCells.set_Value(Type.Missing, data);
return true;
}

The error reads:

System.Runtime.InteropServices.COMException was unhandled

Message="Exception from HRESULT: 0x800A03EC"

Source=""

ErrorCode=-2146827284

I see from a search of various forums that this error apparently can happen
if there are more than 911 (how about that?) characters in the string; and,
when I test, it works fine if I substitute a number of 911 or less for the
"length" part of the code, k - pos3 - 147.

I'm using Office 2003, with SP2 installed.

Does anyone know if there is a solution for this, other than breaking the
string into chunks of 911 characters or less?
 
J

JMiguez

I'm getting an error in my c# app when trying to insert a block of text from
a string array into an Excel cell.

The line of code which reads the string goes like this:

FSInfo[2] = FSPage.Substring(pos3 + 148, k - pos3 - 147);

This line assigns a substring of length (k - pos3 - 147) to a string array
FSInfo[], starting at position pos3 + 148.

The line which generates the error is the set_Value line in this block,
which tries to write the substring into Excel:

public bool InsertDataAt(string start, string[,] data)
        {
            ExcelCOM.Range theCells = MyWorksheet.get_Range(start,
typeMissing);
            theCells.set_Value(Type.Missing, data);
            return true;
        }

The error reads:

System.Runtime.InteropServices.COMException was unhandled

  Message="Exception from HRESULT: 0x800A03EC"

  Source=""

  ErrorCode=-2146827284

I see from a search of various forums that this error apparently can happen
if there are more than 911 (how about that?) characters in the string; and,
when I test, it works fine if I substitute a number of 911 or less for the
"length" part of the code, k - pos3 - 147.

I'm using Office 2003, with SP2 installed.

Does anyone know if there is a solution for this, other than breaking the
string into chunks of 911 characters or less?


I don't have really Office 2003 w/SP2; however, the first thing I
would try is to merge cells.
I am sure with so many characters this won't be numbers -and if they
are apply some formatting.

Let me know if it works,
 
C

Code Deaf

Thanks, Juan, for your reply.

It's not a problem with merged cells. You can copy and paste more than 911
characters into a single cell. It's some bug in the interop, I think -- I
have seen reports of this on other forums.

regards

Oliver
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top