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