Visual Studio 强制我使用完整命名空间,即使添加了引用和 "using"
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
class:System.Windows.Forms
和 Microsoft.Office.Interop.Excel
。完全限定名称允许确定必须使用哪一个。
我使用的是 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
class:System.Windows.Forms
和 Microsoft.Office.Interop.Excel
。完全限定名称允许确定必须使用哪一个。