我正在尝试使用
更改控件的位置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);
答案 0 :(得分:0)
您可以为命名空间使用别名
using Excel = Microsoft.Office.Interop.Excel;
using Drawing = System.Drawing;
并像这样使用
label1.Location = new Drawing.Point(x,y);
查看MSDN参考here