![](/img/trans.png)
[英]Visual studio does not exist in the namespace, but reference is added
[英]Visual Studio forcing me to use full namespace even with reference added and “using” added
我正在使用VS2013社区复制,我已经下载了excel库,但每次说不能区分winforms.application()和excel.application时,它仍然迫使我编写整个命名空间。 它还说“ missing.value”中的“ missing”没有上下文。
此代码几乎完全从MS网站复制而来。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Office.Interop.Excel;
namespace ExcelAuto
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//Initiate Excel Objects
//XlMSApplication oXL;
Microsoft.Office.Interop.Excel.Application oXL;
Workbook oWB;
Worksheet oSheet;
Range oRng;
try
{
//Start Excel and get Application Object.
oXL = new Microsoft.Office.Interop.Excel.Application();
oXL.Visible = true;
//Get a new workbook
oWB= (Microsoft.Office.Interop.Excel._Workbook)(oXL.Workbooks.Add(Missing.Value));
}
catch { }
}
}
}
发生这种情况的原因是,您正在使用存在于两个名称空间中的Application
类: System.Windows.Forms
和Microsoft.Office.Interop.Excel
。 完全限定的名称可以确定必须使用哪个名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.