vb.net Visual Basic 2010 Express - 如何在 Visual Basic 2010 Express 中使用 Excel 函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14168962/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 11:46:48  来源:igfitidea点击:

Visual Basic 2010 Express - How to use excel function in Visual Basic 2010 Express

vb.net

提问by Joyce Sean

I want to use excel function in Visual Basic 2010 Express. I tried to search in the internet to see how to do that.

我想在 Visual Basic 2010 Express 中使用 excel 函数。我试图在互联网上搜索,看看如何做到这一点。

I come across with this solution:

我遇到了这个解决方案:

Module Module1

    Sub Main()
        Imports Excel = Microsoft.Office.Interop.Excel

        Dim oXLApp As New Excel.Application
        Dim ExcelMath As Excel.WorksheetFunction
        ExcelMath = New Excel.WorksheetFunction

        Dim I As Double
        Dim s As Double

        I = ExcelMath.Average(1, 2, 3, 4, 5)
        s = ExcelMath.StDev(1, 2, 3, 4, 5)
        ExcelMath = Nothing
        oXLApp.Quit()
        oXLApp = Nothing

    End Sub

End Module

However, there is error of: 1. Syntax error. 2. Type 'Excel.Applciation" is not defined. 3. Type 'Excel.WorksheetFunction' is not defined.

但是,存在以下错误: 1. 语法错误。2. 未定义类型“Excel.Applciation”。 3. 未定义类型“Excel.WorksheetFunction”。

How should it be resolved?

应该如何解决?

Or is there other simple way to do that?

或者有其他简单的方法可以做到这一点?

Thanks a lot!

非常感谢!

采纳答案by Inisheer

My guess is that you need to add a reference to the Microsoft Excel Object Library. For a brief tutorial, see http://support.microsoft.com/kb/301982(more specifically, step #3).

我的猜测是您需要添加对 Microsoft Excel 对象库的引用。有关简要教程,请参阅http://support.microsoft.com/kb/301982(更具体地说,步骤 3)。

If this doesn't resolve the problem, let us know.

如果这不能解决问题,请告诉我们。

回答by Joseph

Not sure if it has to do with using the Express edition or not, but I had the same problem.

不确定它是否与使用 Express 版本有关,但我遇到了同样的问题。

Whenever I attempted to use Imports Microsoft.Office.Interop.Excelit would not work.

每当我尝试使用Imports Microsoft.Office.Interop.Excel它时都行不通。

I went to Project > Add References > COM > Microsoft Office14.0 Object Libraryand it works now.

我去了 Project > Add References > COM >Microsoft Office14.0 Object Library它现在可以工作了。

回答by Srinivas

Include an import statement at the top : Imports Microsoft.Office.Interop.Excel

在顶部包含一个导入语句: Imports Microsoft.Office.Interop.Excel