• 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

        }

  • 相关阅读:
    springMVC,spring,mybatis全注解搭建框架--第一步,让框架跑起来
    实现excel导入导出功能,excel导入数据到页面中,页面数据导出生成excel文件
    不带插件 ,自己写js,实现批量上传文件及进度显示
    excel转html 实现在线预览
    word和.txt文件转html 及pdf文件, 使用poi jsoup itext心得
    实现图片旋转,滚动鼠标中间对图片放大缩小
    面试中常见问题之线程池与连接池的区别
    实例测试mysqlRR模式和RC模式各种锁情况
    分糖果
    MySQL试题
  • 原文地址:https://www.cnblogs.com/flyerca/p/2021760.html
Copyright © 2020-2023  润新知