在文档级别自定义中从Windows窗体引用Excel工作表 [英] Referencing an excel sheet from a Windows Form in Document Level Customization

查看:105
本文介绍了在文档级别自定义中从Windows窗体引用Excel工作表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我会尝试学习VB.net并从VSTO(VS2012)开始。我正在尝试使用单独的Windows窗体(在加载时显示。)进行Excel文档自定义。我可以在加载文档时打开表格。我找到了许多有关如何在MSDN上的文档中放置Windows窗体控件的示例(并弄清楚了如何做到这一点),但是我在从Windows窗体引用Excel文档的某些部分时遇到了麻烦。

I thought I'd try to learn VB.net and start with some VSTO (VS2012). I'm trying to do an Excel Document Customization with a separate Windows Form in it (.show on load). I can get the form to open on loading the doc. I found lots of examples of how to put Windows Form Controls in the document on MSDN (and figured out how to do that), but I'm having trouble referencing parts of the Excel document from the Windows Form.

例如,在名为Main Control的Windows窗体上,我尝试将此子项添加到按钮:

So for example on the windows form called Main Control I tried to add this sub to a button:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    Try
        Dim baba As Sheet1
        baba.Cells(1, 2).Value = "Llaslmasd"
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
 End Sub

我也尝试过:

        Dim baba As New Sheet1

        Dim baba As WorkSheet
        baba = Sheet1

如果它不是共享成员,或者如果我应该使其共享,该怎么办

What is the correct way to reference the sheet if it is not a shared member, or if I should make it shared, how do I do that?

如果我以编程方式尝试从其他(非合并工作簿,因此更改工作表索引?)中插入工作表,事情将会中断吗?

Will things break if I programatically try to insert sheets from other (non-incorporated workbooks and therefore change sheet index?).

很抱歉,如果我的英语错误或我的问题格式不好,我仍在研究示例。

Sorry if my English is wrong or my formatting of the question is bad, I'm still going over examples.

推荐答案

比调用索引容易得多。在文档级加载项中,工作表将位于Globals下,因此您只需要完全限定要执行的操作即可。

It's much easier than calling for the index. In a document level add-in, the sheets are going to be under Globals, so you just have to fully qualify what you are trying to do.

Globals.Sheet1。 Cells(1,2).Value = Llaslmasd

Globals.Sheet1.Cells(1, 2).Value = "Llaslmasd"

应该工作。

这篇关于在文档级别自定义中从Windows窗体引用Excel工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆