繁体   English   中英

Visual Studio 2010 Excel开发的C#

[英]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; 

或将Sheet5Sheet5 static 如果不创建此类的实例,则无法访问non-static类。

MSDN阅读。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM