将Excel工作簿添加到VB.net应用程序 [英] Add excel workbook to VB.net application

查看:111
本文介绍了将Excel工作簿添加到VB.net应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个仅显示1个表单和按钮的项目。我想做的是一旦单击按钮,它会打开一个预建的excel工作簿。问题是,我需要在应用程序捆绑包中添加excel文件。例如,我将应用程序光盘交给其他人加载到另一台计算机上,然后他们可以运行该应用程序以打开工作簿。我知道如何在我的个人计算机上引用文件,而不是如何在项目内或多或少地独立添加文件。该应用程序是出于库存目的,但需要在多台计算机上打开...这有点像使用VB作为excel工作簿的前端。我对Vb.net知之甚少,但愿意学习。请求逐步演练。

I have a project that I created that only shows 1 form and button. What I am trying to do is once the button is clicked, it opens a pre-built excel workbook. The problem is, I need to add the excel file within the application bundle. For example, I give the application disc to someone else to load on another computer, and then they can run the application to open the workbook. I know how to reference the file on my personal computer, just not how to add it "within" the project, to be, more or less, stand-alone. The application if for inventory purposes but it needs to be opened on numerous computers...this is kinda like using VB as a front end to excel workbook. I know very little about Vb.net but willing to learn. Requesting a walkthrough of steps. Please help!!

推荐答案


  1. 请在解决方案资源管理器中右键单击该项目,然后选择添加>现有项...

  2. 浏览到工作簿,然后单击添加按钮。

  3. 该文件现在应该出现在解决方案资源管理器中项目下方的文件列表中。选择文件。

  4. 在属性窗口中,将复制到输出目录属性更改为始终复制
  5. b $ b
  1. Right-click on the project in the Solution Explorer and select Add>Existing Item...
  2. Browse to the workbook, and click the Add button.
  3. The file should now appear in the list of files below the project in the Solution Explorer. Select the file.
  4. In the Properties window, change the Copy to Output Directory property to Copy always.

这应将工作簿作为可执行文件放在某个文件夹中。这还将复制工作簿并将其添加到您的项目文件夹中。如果您不希望发生这种情况,请使用添加按钮右侧的下拉菜单(请参见上面的第2步),然后选择添加为链接。然后构建将使用在当前位置找到的文件。

This should put the workbook in the some folder as the executable. This will also make a copy of the workbook and add it to you project folder. If you don't want that to happen, the use the drop-down on the right-hand side of the Add button (see Step 2 above), and select Add as Link. Then builds will use the file as it's found in its current location.

要以编程方式打开工作簿,请执行以下操作:

To open the workbook programmatically, do:

Dim filename as String = My.Application.Info.DirectoryPath & System.IO.Path.DirectorySeparatorChar & "WorkbookName.xlsx"
Process.Start(filename)

此示例假定文件名为 WorkbookName.xlsx ,则需要对其进行更改以匹配文件名。

This example assumes that the file is named, WorkbookName.xlsx, you'll need to change it to match the name of your file.

这篇关于将Excel工作簿添加到VB.net应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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