Excel Addin .NET, Read Cell Values

  • Thread starter Manuel Wenk [MCP ASP & WinForms]
  • Start date
M

Manuel Wenk [MCP ASP & WinForms]

Hi, I've got a problem developing an Excel Addin. I'm trying to read values
out of single Cells in a worksheet, I'm using the
Microsoft.Office.Interop.Excel.dll for .NET
together with Excel 2003.

I've splitted the code a little bit to circle in the Problem. Imediatley at
the first statement Cell[...] the Programm throws an COMException
(DISP_E_TYPEMISTMATCH).

Sheet contains a valid worksheet reference, CellID contains "G3" wich is an
vaild Cell with an Value in it.

Can someone give me a hint or any other Code to read single Values out of
Worksheet-Cells ?

private object ReadCell(string cellId, Excel.Worksheet sheet)
{
object o1 = sheet.Cells[cellId, Type.Missing];
Excel.Range range = (Excel.Range)o1;
object rv = range.Value2;
return rv;
}


Thanks in advance,
Manuel Wenk
 
X

XL-Dennis

Hi Manuel,

At present I don't have access to my developer machine but I believe that
the following article by Ken Gets is a good starting point:

Understanding the Excel Object Model from a .NET Developer's Perspective
http://msdn.microsoft.com/newsgroup...r=US&mid=cc87ae45-08bc-4f42-a5cf-a174e8fcf420

I will tomorrow post an example if the issue still remains.

---------------
With kind regards,
Dennis
Weekly Blog .NET & Excel: http://xldennis.wordpress.com/
My English site: http://www.excelkb.com/default.aspx
My Swedish site:
http://www.xldennis.com/
 
M

Manuel Wenk [MCP ASP & WinForms]

Hi Dennis, thank's for your hint. Unfortunately I don't see any Info of how
to access a cells value directly in the document, could you post the example
you spoke of?

Thanks!
Manuel Wenk
 
M

Manuel Wenk [MCP ASP & WinForms]

Hi there,

I've just solved it:

private object ReadCell(string cellId, Excel.Worksheet sheet)
{
Excel.Range range = sheet.get_Range(cellId, Type.Missing);
return range.Value2;
}


Tanks!
 

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