Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net VB中的趋势线常数_Vb.net_Excel - Fatal编程技术网

Vb.net VB中的趋势线常数

Vb.net VB中的趋势线常数,vb.net,excel,Vb.net,Excel,我是VB新手,但看起来这应该很简单。我试图在我的VB项目中获得线性趋势线的常数 Dim WStemp1 As WorksheetFunction Dim WStemp2 As WorksheetFunction X1_home = WStemp1.Index(WStemp2.LinEst(y_values, x_values), 1, 1) C1_home = WStemp1.Index(WStemp2.LinEst(y_values, x_values), 1

我是VB新手,但看起来这应该很简单。我试图在我的VB项目中获得线性趋势线的常数

    Dim WStemp1 As WorksheetFunction
    Dim WStemp2 As WorksheetFunction

    X1_home = WStemp1.Index(WStemp2.LinEst(y_values, x_values), 1, 1)
    C1_home = WStemp1.Index(WStemp2.LinEst(y_values, x_values), 1, 2)
这段代码在vba中运行良好,但出现以下错误

    An unhandled exception of type 'System.NullReferenceException' occurred in myApp.exe
    Additional information: Object reference not set to an instance of an object.
    If there is a handler for this exception, the program may be safely continued.

非常感谢您的帮助

您必须从Excel应用程序中恢复工作表功能对象。例如:

Dim App As New Excel.Application
Dim ExcelFunc As Excel.WorksheetFunction = App.WorksheetFunction

'Use the excel function
Dim avg As Double 
avg = ExcelFunc.Average(1, 2, 3, 4, 5)

'release objects and terminate Excel application
ExcelFunc = Nothing
App.Quit()
App = Nothing

干杯

展示如何实例化
WStemp1
WStemp2
就是这样,我不启动它们。您建议如何执行此操作?
WorksheetFunction
是Excel应用程序对象的属性-您的项目中是否有对Excel的引用?通常您会使用类似于
xlApp.WorksheetFunction
的东西,其中
xlApp
是您的Excel应用程序实例。