程序笔记
随心而记

程序代码如下:(但要引入Excel类库)

Public Class clsExcelClass
    Private m_xlsObj As Excel.Application
    Private m_xlsWbk As Excel.Workbook
    Private m_xlsSht As Excel.Worksheet

    Public ReadOnly Property ColNum() As Integer
        Get
            Return m_xlsSht.UsedRange.Columns.Count
        End Get
    End Property

    Public ReadOnly Property RowNum() As Integer
        Get
            Return m_xlsSht.UsedRange.Rows.Count
        End Get
    End Property

    Public ReadOnly Property GetRangeValue(ByVal RangeIndex As String) As Integer
        Get
            Return m_xlsSht.Range(RangeIndex).Value
        End Get
    End Property

    Public ReadOnly Property GetCellValue(ByVal intRow As Integer, ByVal intCol As Integer) As Integer
        Get
            Return m_xlsSht.Cells(intRow, intCol).Value
        End Get
    End Property

    Public Shared Sub Open(ByVal FilePath As String)
        m_xlsObj = New Excel.Application
        m_xlsObj.DisplayAlerts = False
        m_xlsWbk = m_xlsObj.Workbooks.Open(FilePath)
        m_xlsSht = m_xlsWbk.Sheets(1)
    End Sub

    Public Shared Sub Close()
        m_xlsObj.Quit()
        m_xlsWbk = Nothing
        m_xlsSht = Nothing
        m_xlsObj = Nothing
    End Sub

End Class
如有不足之处,请给予指出,谢谢!

posted on 2008-09-15 11:21    阅读(1922)  评论(0)    收藏  举报