[英]Custom Control for XSL editing/development C# Visual Studio 2010
[英]C# for visual studio 2010 excel development
我創建了一個Excel 2007工作簿,其中包含隱藏的工作表。一個未隱藏的工作表具有命令按鈕,每個命令按鈕上都有每個工作表名稱。 單擊命令按鈕時,應使隱藏的工作表可見,並將焦點放在該工作表上。 下面的代碼返回此錯誤:
非靜態字段,方法或屬性“ Microsoft.Office.Tools.Excel.WorksheetBase.Visible get”需要對象引用。
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml.Linq;
using Microsoft.Office.Tools.Excel;
using Microsoft.VisualStudio.Tools.Applications.Runtime;
using Excel = Microsoft.Office.Interop.Excel;
using Office = Microsoft.Office.Core;
namespace TestProj
{
public partial class Sheet17
{
private void Sheet17_Startup(object sender, System.EventArgs e)
{
}
private void Sheet17_Shutdown(object sender, System.EventArgs e)
{
}
#region VSTO Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.button1.Click += new System.EventHandler(this.button1_Click);
this.Startup += new System.EventHandler(this.Sheet17_Startup);
this.Shutdown += new System.EventHandler(this.Sheet17_Shutdown);
}
#endregion
private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
Sheet5 How = new Sheet5();
How.Visible = Excel.XlSheetVisibility.xlSheetVisible;
}
}
}
有人可以幫我解決這個錯誤嗎?
這樣使用;
Sheet5 mySheet = new Sheet5();
mySheet.Visible = Excel.XlSheetVisibility.xlSheetVisible;
或將Sheet5
類Sheet5
static
。 如果不創建此類的實例,則無法訪問non-static
類。
從MSDN
閱讀。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.