使用 Microsoft.Office.Interop.Excel 时出现错误; C# 中带有控制新点语法的命名空间

I'm getting error when using Microsoft.Office.Interop.Excel; namespace with controls new point syntax in C#

我正在尝试使用

更改控件的位置
label1.Location = new Point(x,y);

但我还想将数据从数据网格视图导出到 excel,为此我正在使用

using Microsoft.Office.Interop.Excel;

但是当我使用它时,命名空间编译器在

中显示错误
label1.Location = new Point(x,y);

Error : 'Point' is an ambiguous reference between 'System.Drawing.Point' and 'Microsoft.Office.Interop.Excel.Point'

导出数据到excel的代码:

Microsoft.Office.Interop.Excel.Application Excel = new Microsoft.Office.Interop.Excel.Application();

    Workbook wb = Excel.Workbooks.Add(XlSheetType.xlWorksheet);

    Worksheet ws = (Worksheet)Excel.ActiveSheet;

    Excel.Visible = true;

    ws.Cells[1, 1] = "ID";

    ws.Cells[1, 2] = "Products Name";

    ws.Cells[1, 3] = "Products Id";

    ws.Cells[1, 4] = "Products Price";

    ws.Cells[1, 5] = "Selling Price";

    for (int j = 2; j <= dataGridView1.Rows.Count; j++)
    {
        for (int i = 2; i <= 5; i++)
        {
            ws.Cells[j, i] = dataGridView1.Rows[j - 2].Cells[i - 1].Value;
        }
    }

新点代码:

linkLabel7.Show();

linkLabel7.Location = new Point(293, 59);

您可以为命名空间使用别名

using Excel = Microsoft.Office.Interop.Excel;
using Drawing = System.Drawing;

并像这样使用它

label1.Location = new Drawing.Point(x,y);

查看 MSDN 参考资料here