[英]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參考
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.