如何在VB.NET 2010中调用excel函数 [英] How to call excel function in VB.NET 2010
问题描述
我想从VB.Net 2010使用Excel的XIRR功能。任何人都可以告诉我如何做到这一点。请帮助我,这是不紧急的。我已经尝试了以下代码,但我收到错误工作表函数类的XIRR方法失败
我试过的:
这是我用过的代码
Imports Excel = Microsoft.Office.Interop.Excel
Public Class Class1
Dim excelapp As New Excel.Application
Private Sub Sub1
Dim ClAmtArr As ArrayList
Dim DtArr As ArrayList
ClAmtArr = New ArrayList()
DtArr = New ArrayList( )
每行作为DataRow在ds_record.Tables(0)。行
ClAmtArr.Add(-dbl_ClSellAmt)
dtArr.Add( FormatDateTime(row.item(PayinDate),DateFormat.ShortDate))
dbl_TotAmt = dbl_TotAmt + dbl_SellAmt
下一页
ClAmtArr.Add( dbl_TotAmt)
dtArr.Add(dtb_asOnDate.Value)
excelapp =新的Excel.Application()
dbl_AnnualRet = excelapp.WorksheetFunction.Xirr( ClAmtArr,DtArr)< br $>
结束子
结束类
I want to Use XIRR Function of Excel From VB.Net 2010. Can any one tell me how to do this. Pls help me out it is little urgent. I have tried the below code but i am getting error as "XIRR method of worksheetfunction class failed"
What I have tried:
This is the code i have used
Imports Excel = Microsoft.Office.Interop.Excel
Public Class Class1
Dim excelapp As New Excel.Application
Private Sub Sub1
Dim ClAmtArr As ArrayList
Dim DtArr As ArrayList
ClAmtArr = New ArrayList()
DtArr = New ArrayList()
For Each row As DataRow In ds_record.Tables(0).Rows
ClAmtArr.Add(-dbl_ClSellAmt)
dtArr.Add(FormatDateTime(row.item("PayinDate"),DateFormat.ShortDate))
dbl_TotAmt=dbl_TotAmt+dbl_SellAmt
Next
ClAmtArr.Add(dbl_TotAmt)
dtArr.Add(dtb_asOnDate.Value)
excelapp = New Excel.Application()
dbl_AnnualRet = excelapp.WorksheetFunction.Xirr(ClAmtArr, DtArr)
End Sub
End Class
推荐答案
而不是调用Excel,它最好重新实现.NET代码中的函数。
此StackOverflow主题 [ ^ 一>]。您可以创建C#库并从VB.NET代码中调用它,或者在需要时将C#代码转换为VB.NET。
Rather than calling Excel, it would be better to reimplement the function in .NET code.
There are several C# implementations in this StackOverflow thread[^]. You can either create C# library and call it from your VB.NET code, or convert the C# code to VB.NET if required.
这篇关于如何在VB.NET 2010中调用excel函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!