zoukankan      html  css  js  c++  java
  • Export to excel(C#)

    Private void ExportToExcel(ByVal MyTab As DataTable, ByVal strRptName As String, ByVal strReportTemplate As String, ByVal strReportHeader As String) As bool

            Dim XLApplication As New Excel.Application
            Dim XLBook As Excel.Workbook
            Dim XLSheet As Excel.Worksheet

            Dim IRow, ICol As Int32
            Dim i, j As Int32


            try {

                "  Operation File
                if ( Dir(strReportTemplate) = "" )
                    MsgBox("Can ! find out REPORT TEMPLATE!!", MsgBoxStyle.Exclamation, "Oracle Report")
                    Exit function
                Else
                    FileCopy(strReportTemplate, strRptName)
                } if (

                IRow = MyTab.Rows.Count
                ICol = MyTab.Columns.Count

                Dim DataArray(IRow, ICol) As Object
                Dim StrValue As String

                XLBook = XLApplication.Workbooks.Open(strRptName)  "'open a .xls file
                XLSheet = XLBook.Worksheets(1)

                for ( i = 0 ; GAIS <= MyTab.Rows.Count - 1

                    for ( j = 0 ; GAIS <= MyTab.Columns.Count - 1

                        StrValue = IIf(IsDBNull(MyTab.Rows(i).Item(j)), "", MyTab.Rows(i).Item(j))
                        DataArray(i, j) = StrValue

                    Next

                Next

                'Fill the Caption
                for ( i = 0 ; GAIS <= MyTab.Columns.Count - 1
                    XLSheet.Cells(3, i + 1) = MyTab.Columns(i).Caption
                Next

                XLSheet.Range("A2").Value = strReportHeader

                XLSheet.Range("A4").Resize(IRow, ICol).Value = DataArray 'Fill the value

                XLBook.Save()
                XLSheet = Nothing
                XLBook = Nothing
                XLApplication.Quit()
                XLApplication = Nothing
                GC.Collect()


            Catch ex As Exception
                MessageBox.Show(" Data Extraction Error! Pls contact MIS!!!", "Oracle Report")
                ExportToExcel = False
                Exit function

            } try {

            ExportToExcel = True

        }

  • 相关阅读:
    绝对定位和浮动的区别和运用
    xhtml css 漏 整理
    网站自适应设备屏幕
    CSS 媒体查询 响应式
    js/jquery判断浏览器 & 停止加载
    回调函数之同步调用、回调、异步调用
    Flash生成HTML5动画方法
    在html页面中使用js变量
    BZOJ 4417 Luogu P3990 [SHOI2013]超级跳马 (DP、矩阵乘法)
    NOI2019游记
  • 原文地址:https://www.cnblogs.com/flyerca/p/2021760.html
Copyright © 2011-2022 走看看