I have a C# AddIn for Excel in which I get the Excel.Application object as follows:
I can get all sorts of information about the spreadsheet via methods on applicationObject, but I am unable to change anything on the spreadsheet through this object. If I do this ...
... or this ...
... or anything else which attempts to change the contents of the spreadsheet, I get an HRESULT 0x800A03EC exception.
Ive searched around the net, but I cant find anything which helps me get past this error. Some people have talked about localization as a possible cause of errors like this, but if I do the following before making the offending calls, I still get the same exception:
Therefore, I dont think that localization is the issue.
Could it be that COM Interop doesnt permit me to change anything on the spreadsheet via that Excel.Application object? If so, is there any other way to accomplish this within a COM-Interop-based AddIn?
Thanks in advance.
Code:
private Excel.Application applicationObject;
public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode,
object addInInst, ref System.Array custom)
{
applicationObject = (Excel.Application) application;
}
Code:
applicationObject.calculateFull();
Code:
Excel.Worksheet ws = (Excel.Worksheet) applicationObject.Worksheets[1];
Excel.Range range = (Excel.Range) ws.Cells;
int cc = ws.UsedRange.Columns.Count;
for (int c = 1; c <= cc; c++)
{
range.set_Item(10, c, "test"); // row 10 starts out empty and unlocked
}
Ive searched around the net, but I cant find anything which helps me get past this error. Some people have talked about localization as a possible cause of errors like this, but if I do the following before making the offending calls, I still get the same exception:
Code:
System.Threading.Thread thisThread =
System.Threading.Thread.CurrentThread;
thisThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
Could it be that COM Interop doesnt permit me to change anything on the spreadsheet via that Excel.Application object? If so, is there any other way to accomplish this within a COM-Interop-based AddIn?
Thanks in advance.
Last edited by a moderator: