Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to insert values into excel cell using vsto I write code on user control button but it is giving error


What I have tried:

private void btnGetExcl_Click(object sender, EventArgs e)
       {


Excel.Worksheet activeSheet = ((Excel.Worksheet)Application.ActiveSheet);
                      activeSheet.Cells[0, 0] = text;


}

here for
Application
it is giving Error

a
Severity	Code	Description	Project	File	Line	Suppression State
Error	CS0104	'Application' is an ambiguous reference between 'Microsoft.Office.Interop.Excel.Application' and 'System.Windows.Forms.Application'	ExcelAddIn1	D:\VSTO_Vinayak\ExcelAddIn1\ExcelAddIn1\UserControl1.cs	213	Active
Posted
Updated 21-Mar-18 3:59am

1 solution

The compiler cannot determine which Application object you want to use, so you have to specify the fully qualified namespace. Try it this way:

C#
Excel.Worksheet activeSheet = ((Excel.Worksheet)(Microsoft.Office.Interop.Excel.Application.ActiveSheet));


Learn how to use google. Answers to your questions can be easily found, and is faster than asking a question on a forum, and waiting for a suitable answer. I'm not saying this because I'm tired of answering your questions. I'm saying this because debugging and using google are the two MOST important skills you can use to develop your code faster.
 
Share this answer
 
v2
Comments
paul_vin 22-Mar-18 2:11am    
Hi, thanks for advice, I know on forum it take time to answer, but when i search things on google i am not getting it I don't know how it happen. Mostly I trying to search thing on google.
paul_vin 22-Mar-18 3:39am    
hi this is also giving error

Excel.Worksheet activeSheet = ((Excel.Worksheet)(Microsoft.Office.Interop.Excel.Application.ActiveSheet));

an object reference is required for the non static field method or property '_application.activesheet'

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900