Excel Helper 源代码(VB.NET)

 自己写了一个对Excel操作的类, 封装了Excel的通常的操作,以简化生成 Excel 报表的代码量。

代码基于 .net 2.0, Excel 2003

该 Assembly 共有两个类:

1.  XlsReport.vb

Imports  System
Imports  Excel  =  Microsoft.Office.Interop.Excel

Public   Enum XlCopyAction
    Paste
    Insert
End Enum


Public   Enum XlBorders
    xlDiagonalDown 
= Excel.XlBordersIndex.xlDiagonalDown
    xlDiagonalUp 
= Excel.XlBordersIndex.xlDiagonalUp
    xlEdgeLeft 
= Excel.XlBordersIndex.xlEdgeLeft
    xlEdgeTop 
= Excel.XlBordersIndex.xlEdgeTop
    xlEdgeBottom 
= Excel.XlBordersIndex.xlEdgeBottom
    xlEdgeRigth 
= Excel.XlBordersIndex.xlEdgeRight
    xlInsideHorizontal 
= Excel.XlBordersIndex.xlInsideHorizontal
    xlInsideVertical 
= Excel.XlBordersIndex.xlInsideVertical
End Enum


Public   Enum XlLineStyle
    xlContinuous 
= Excel.XlLineStyle.xlContinuous
    xlDash 
= Excel.XlLineStyle.xlDash
    xlDashDot 
= Excel.XlLineStyle.xlDashDot
    xlDashDotDot 
= Excel.XlLineStyle.xlDashDotDot
    xlDot 
= Excel.XlLineStyle.xlDot
    xlDouble 
= Excel.XlLineStyle.xlDouble
    xlLineStyleNone 
= Excel.XlLineStyle.xlLineStyleNone
    xlSlantDashDot 
= Excel.XlLineStyle.xlSlantDashDot
End Enum


Public   Enum XlBorderWight
    xlHairline 
= Excel.XlBorderWeight.xlHairline
    xlMedium 
= Excel.XlBorderWeight.xlMedium
    xlThick 
= Excel.XlBorderWeight.xlThick
    xlThin 
= Excel.XlBorderWeight.xlThin
End Enum


Public   Enum XlFontStyle
    xlStrikethrough
    xlSuperscript
    xlSubscript
    xlOutlineFont
    xlShadow
    xlBold
    xlItalic
    xlUnderlineDouble
    xlUnderlineSingle
    xlNone
End Enum


Public   Enum XlCellFormat
    xlWrapTest
    xlShrinkToFit
    xlNone
End Enum


Public   Enum XlHAlign
    xlCenter 
= Excel.XlHAlign.xlHAlignCenter
    xlCenterAcrossSelection 
= Excel.XlHAlign.xlHAlignCenterAcrossSelection
    xlDistributed 
= Excel.XlHAlign.xlHAlignDistributed
    xlFill 
= Excel.XlHAlign.xlHAlignFill
    xlGeneral 
= Excel.XlHAlign.xlHAlignGeneral
    xlJustify 
= Excel.XlHAlign.xlHAlignJustify
    xlLeft 
= Excel.XlHAlign.xlHAlignLeft
    xlRight 
= Excel.XlHAlign.xlHAlignRight
End Enum


Public   Enum XlVAlign
    xlBottom 
= Excel.XlVAlign.xlVAlignBottom
    xlCenter 
= Excel.XlVAlign.xlVAlignCenter
    xlDistributed 
= Excel.XlVAlign.xlVAlignDistributed
    xlJustify 
= Excel.XlVAlign.xlVAlignJustify
    xlTop 
= Excel.XlVAlign.xlVAlignTop
End Enum


Public   Enum XlFillPattern
    xlNone 
= Excel.XlPattern.xlPatternNone
    xlSolid 
= Excel.XlPattern.xlPatternSolid
    xlAuto 
= Excel.XlPattern.xlPatternAutomatic
    xlChecker 
= Excel.XlPattern.xlPatternChecker
    xlCrissCross 
= Excel.XlPattern.xlPatternCrissCross
    xlDown 
= Excel.XlPattern.xlPatternDown
    xlUp 
= Excel.XlPattern.xlPatternUp
    xlHorizontal 
= Excel.XlPattern.xlPatternHorizontal
    xlVertical 
= Excel.XlPattern.xlPatternVertical
    xlGrid 
= Excel.XlPattern.xlPatternGrid
    xlGray8 
= Excel.XlPattern.xlPatternGray8
    xlGray16 
= Excel.XlPattern.xlPatternGray16
    xlGray25 
= Excel.XlPattern.xlPatternGray25
    xlGray50 
= Excel.XlPattern.xlPatternGray50
    xlGray75 
= Excel.XlPattern.xlPatternGray75
    xlLightDown 
= Excel.XlPattern.xlPatternLightDown
    xlLightHorizontal 
= Excel.XlPattern.xlPatternLightHorizontal
    xlLightUp 
= Excel.XlPattern.xlPatternLightUp
    xlLightVertical 
= Excel.XlPattern.xlPatternLightVertical
    xlSemiGray75 
= Excel.XlPattern.xlPatternSemiGray75
End Enum


Public   Class XlsReport

プロパティ

Reportの操作

セルの操作

行の操作

列の操作

属性の操作

データの操作

End Class

2. XlsReportException.vb

Public   Enum XlErrorNo
    errNoError 
= 0
    errOpen
    errSave
    errClose
    errSheet
    errAddSheet
    errValue
    errFormula
    errClear
    errCopy
    errPaste
    errInsert
    errDelete
    errHide
    errFormat
    errPageBreak
    errCell
    errRow
    errColumn
    errData
    errAttr
    errParam
    errFileType
    errAppError
    errVersion
    errOther
End Enum


Public   Class XlsReportException
    
Inherits Exception

    
Private menmErrorNo As XlErrorNo

    
Private mstrErrorMessage As String

    
Public Property ErrorNo() As XlErrorNo
        
Get
            
Return menmErrorNo
        
End Get
        
Set(ByVal value As XlErrorNo)
            menmErrorNo 
= value
        
End Set
    
End Property


    
Public Property ErrorMsg() As String
        
Get
            
Return mstrErrorMessage
        
End Get
        
Set(ByVal value As String)
            mstrErrorMessage 
= value
        
End Set
    
End Property


    
Public Sub New(ByVal ex As Exception, Optional ByVal errorNo As XlErrorNo = XlErrorNo.errOther, _
                   
Optional ByVal errorMsg As String = "")
        menmErrorNo 
= errorNo
        mstrErrorMessage 
= errorMsg
        
If errorMsg = "" AndAlso ex IsNot Nothing Then
            mstrErrorMessage 
= ex.Message
        
End If
    
End Sub

End Class

 

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值