在 asp.net 使用 excel

記得在 Web.config 上加上這一行

 <system.web>
<identity impersonate="true" userName="Admin" password="pwd" />

userName 與password 打上可以執行excel的帳號與密碼

以上是使用excel 2003 函數的範例:(記得要將 excle的元件參考進來)

Option Strict Off
Imports System
Imports System.Reflection ' For Missing.Value and BindingFlags
Imports System.Runtime.InteropServices ' For COMException
Imports Microsoft.Office.Interop.Excel

Public Class ExTools

    Private app As Application

    Sub New()
        app = New Application
    End Sub


    Public Function getNORMSINV(ByVal score As Double, ByVal aveScore As Double, ByVal STDEVScore As Double) As Double
        Try
            If app Is Nothing Then
                app = New Application
            End If

            Return app.WorksheetFunction.NormSInv(app.WorksheetFunction.NormDist(score, aveScore, STDEVScore, True))
            ' app.Quit()

            'Return d

        Catch ex As Exception
            app.Quit()
        End Try

        'Dim iWorksheetFunction1 As IWorksheetFunction
        'Return iWorksheetFunction1.NormSInv(iWorksheetFunction1.NormDist(score, aveScore, STDEVScore, True))

    End Function

    Public Sub appQuit()
        app.Quit()
    End Sub

End Class

文章標籤
全站熱搜
創作者介紹
創作者 hsiung03 的頭像
hsiung03

hsiung.博格 ERP軟體

hsiung03 發表在 痞客邦 留言(0) 人氣(1)