Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用Microsoft.Office.Interop.Excel时出错;C中带有新点语法的命名空间控件_C#_Excel_Location_Controls - Fatal编程技术网

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

C# 使用Microsoft.Office.Interop.Excel时出错;C中带有新点语法的命名空间控件,c#,excel,location,controls,C#,Excel,Location,Controls,我正在尝试使用更改控件的位置 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 'Mi

我正在尝试使用更改控件的位置

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;
        }
    }

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

using Excel = Microsoft.Office.Interop.Excel;
using Drawing = System.Drawing;
像这样使用它

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

查看MSDN参考资料

谢谢。成功了。但现在我在excel中导出数据,excel中只显示了表coulms名称,而不是数据。您需要导出的完整代码吗?我用互联网制作了这个代码,不是我自己的,请检查这个问题。我给你这个问题的链接。那是另一个问题。如果我的答案对你有用,请将我的答案标记为已接受。对于不同的问题,请使用不同的问题。请检查此项。。。我给你这个问题的链接。
label1.Location = new Drawing.Point(x,y);