ExcelToXML

Hi,
I discovered VSTO a week ago, so it might be a beginner error Smile.
My program is quite simple. I created a custom task pane with one button.
When the button is clicked, the following method is called :

Code Snippet

public void CallTest()
{
oWorksheet = (Excel.Worksheet)Application.Worksheets.get_Item(1);

Excel.Range myRange = (Excel.Range)oWorksheet.Rows.get_Item(1, System.Type.Missing);

int length = myRange.Columns.Count; // length = 16384
int col = myRange.Column; // col = 1
int row = myRange.Row; // row = 1
object item = myRange.get_Item(1, 1);
}


When the program reaches the get_Item call, it throws a COMException with HRESULT = 0x800A03EC.

Any ideas what could be doing this

PS: I'm using an english version of VS 2005 with a french version of Office (Excel 2007). My regional options are set to France.


Re: Visual Studio Tools for Office getting a HRESULT = 0x800A03EC error when using get_Item

Andrew Cherry [MSFT]

Welcome to the VSTO world!

My first suspicion relates the infamous Excel "LCID issue." Some Excel object model calls expect the Locale to be set to US-English. VBA has no problems because it always acts as if it's in the US-English Locale. Especially given that you're working with French Office, this strikes me as a potential point of failure.

Eric Carter has written a blog post on both the problem, some solutions, and our technologies in VSTO 2005 that should resolve the issue:

http://blogs.msdn.com/eric_carter/archive/2005/06/15/429515.aspx

Good luck!

Andrew






Re: Visual Studio Tools for Office getting a HRESULT = 0x800A03EC error when using get_Item

ExcelToXML


Thanks for the reply.
I followed the link you gave me and tried differents solutions. But I still get the 0x800A03EC error.
However, the call trace isn't the same (big progress Wink ).
At first, the call trace was something like this :

Code Snippet

Server stack trace:


Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at Microsoft.Office.Interop.Excel.Range.get__Default(Object RowIndex, Object ColumnIndex)
at TestAddin.ThisAddIn.CallTest()


When I comment this line of code (generated by VS) and put this one instead :

Code Snippet

//this.Application = (Excel.Application)Microsoft.Office.Tools.Excel.ExcelLocale1033Proxy.Wrap(typeof(Excel.Application), this.Application);
this.Application = (Excel.Application)Microsoft.Office.Tools.Excel.ExcelLocale1033Proxy.Unwrap(this.Application);


I'm getting the following stack trace :

Code Snippet

at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Microsoft.Office.Interop.Excel.Range.get__Default(Object RowIndex, Object ColumnIndex)
at TestAddin.ThisAddIn.CallTest()



The ExcelLocale1033Proxy.Unwrap() method is used to pass the locale ID of the current thread to the Excel object model, instead of locale ID 1033 (English, United States).

I think this is the good thing to do but I still get some errors...
Any help greatly appreciated






Re: Visual Studio Tools for Office getting a HRESULT = 0x800A03EC error when using get_Item

ExcelToXML


Ok, I think I found a way to get around this problem.
Instead of getting every element one after the other (which obviously doesn't work Smile),
I get the whole row in bi-dimensionnal object array and use it to process the elements of the row.

Code Snippet

public void CallTest()
{
oWorksheet = (Excel.Worksheet)Application.Worksheets.get_Item(1);

Excel.Range myRange = (Excel.Range)oWorksheet.Rows.get_Item(1, System.Type.Missing);

Object[,] myArray = myRange.Value2 as Object[,];

// Process elements of my array
}