zoukankan      html  css  js  c++  java
  • Export to excel

      Private Function ExportToExcel(ByVal MyTab As DataTable, ByVal strRptName As String, ByVal    strReportTemplate As String, ByVal strReportHeader As String) As Boolean

            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) = "" Then
                    MsgBox("Can not find out REPORT TEMPLATE!!", MsgBoxStyle.Exclamation, "Oracle Report")
                    Exit Function
                Else
                    FileCopy(strReportTemplate, strRptName)
                End 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 To MyTab.Rows.Count - 1

                    For j = 0 To 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 To 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

            End Try

            ExportToExcel = True

        End Function

  • 相关阅读:
    【小程序】请求与封装
    【小程序】生命周期
    【小程序】项目结构
    【笔记】vue-cli 开发环境中跨域连接后台api(vue-resource 跨域post 请求)
    【笔记】npm 安装 vue-cli
    【笔记】css 实现宽度自适应屏幕 高度自适应宽度
    【笔记】css 1像素边框
    【笔记】让360浏览器用chrome 内核渲染你的网页
    【实践】require.js + r.js 代码打包压缩初体验
    【笔记】学校项目开发中所了解的一些浏览器之间的差异
  • 原文地址:https://www.cnblogs.com/flyerca/p/2021759.html
Copyright © 2011-2022 走看看