VS2012 excel应用程序

编程入门 行业动态 更新时间:2024-10-28 02:32:51
本文介绍了VS2012 excel应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我目前正在开发一个使用VS2012和VB.Net实现VSTO的Excel项目。我有一个基本工作簿,其中有一个默认工作表,它根据下面的代码复制ADD命令。下面的代码工作正常,但我看不到如何访问这个添加的表。任何人都可以建议我如何引用这张新表吗?

I am currently developing a Excel project with VS2012 and VB.Net implementing VSTO. I have a base workbook which has a default sheet which from an ADD command ic copied as per the code below. The code below works fine but I cannot see how to access this added sheet. Can anyone suggest how I reference this new sheet?

Dim noSheets As Integer noSheets = Globals.ThisWorkbook.Worksheets.Count Globals.Sheet2.Copy(after:=Globals.ThisWorkbook.Sheets(noSheets)) Globals.Sheet2.Visible = Excel.XlSheetVisibility.xlSheetVisible

任何指针赞赏 Phil

Any pointers appreciated Phil

推荐答案

我的避风港没有使用VSTO,但是使用VBA,你可以通过工作表列表进行迭代。我相信VSTO必须有类似的东西。 VSTO有工作表吗?添加一个快速循环,检查工作表名称,并查看调用的内容。 I haven't used VSTO, but with VBA you can itterate through the list of sheets. I'm sure VSTO must have something similar. Does VSTO have a count of worksheets? Add a quick loop, check the worksheets name, and see what is is called.

您可以使用它来获取名称的工作表: You can use this to get the worksheet by name: private Excel.Worksheet GetWorksheetByName(string name) { foreach (Excel.Worksheet worksheet in this.Worksheets) { if (worksheet.Name == name) { return worksheet; } } throw new ArgumentException(); } private void ActivateWorksheetByName(string name) { GetWorksheetByName(name).Activate(); }

Source [ ^ ] 奇怪的是,工作表无法使用Copy()函数返回对创建的工作表的引用,重要的是要注意创建的工作表是Microsoft.Office.Interop.Excel.Worksheet而不是Micorosoft.Office.Tools.Excel.Worksheet。我认为应该有一种方法可以通过索引获得它,但我找不到它所以也许这个答案没有帮助......

Source[^] It is odd that the worksheet doesn't have a way to return a reference to the created worksheet with the Copy() function, and it is important to note that the created worksheet is a Microsoft.Office.Interop.Excel.Worksheet and not a Micorosoft.Office.Tools.Excel.Worksheet. I think there should be a way to get it by index, but I can't find it so maybe this answer isn't helpful...

带上一粒盐作为我没有VSTO,但根据我的理解,它是标准办公室互操作的扩展包装。 复制工作表后,新创建的工作表成为活动工作表;因此你应该能够用它来创建一个引用。 对于标准的interop,语法是: Take this with a grain of salt as I do not have VSTO, but based on my understanding it is an extended wrapper around the standard office interop. After copying a worksheet, the newly created worksheet becomes the activeworksheet; therefore you should be able to use that to create a reference. For standard interop the syntax would be: Dim newcopy As Excel.Worksheet = DirectCast(app.ActiveSheet, Excel.Worksheet)

其中app是对Excel应用程序的引用。 我相信VSTO语法将是:

where "app" is a reference to the Excel application. I believe the VSTO syntax would be:

Dim newcopy As Excel.Worksheet = DirectCast(Me.Application.ActiveSheet, Excel.Worksheet)

更多推荐

VS2012 excel应用程序

本文发布于:2023-11-13 01:22:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1583017.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   excel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!