⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 excelexport.vb

📁 使用Access数据库演示的任务分配管理程序 一个使用ADO.NET基于Microsoft Access数据库演示的任务分配管理的程序
💻 VB
字号:
'---------------------------------------------------------------------
'  This file is part of the Microsoft .NET Framework SDK Code Samples.
' 
'  Copyright (C) Microsoft Corporation.  All rights reserved.
' 
' This source code is intended only as a supplement to Microsoft
' Development Tools and/or on-line documentation.  See these other
' materials for detailed information regarding Microsoft code samples.
' 
' THIS CODE AND INFORMATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY
' KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
' IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
' PARTICULAR PURPOSE.
'---------------------------------------------------------------------

'---------------------------------------------------------------------
' Disabled in this version
'
' Requires: Excel.Interop.dll
'              Interop.Microsoft.Office.Core.dll
'              Interop.VBIDE.dll
'
' Download Available: http://support.microsoft.com/kb/897646/en-us?spid=2529&sid=global 
'
'---------------------------------------------------------------------

'Option Strict Off 'Latebinding

'Imports Excel

'Public Class ExcelExport
'    ' Export to Excel if it is installed on their machine

'    Public Sub ExportTasks(ByVal TasksData As DataSet, ByVal TasksDataView As DataView, ByVal TasksGrid As DataGridView)

'        Dim excelApp As Excel.Application
'        Dim workBook As Excel.Workbook
'        Dim ws As Excel.Worksheet
'        Dim r As Excel.Range
'        Dim c As Excel.Chart
'        Dim row As Integer = 1
'        Dim cell As Integer = 1
'        Dim priorityHigh, priorityNormal, priorityLow As Integer

'        Try
'            'which ever version of Excel was referenced to build the interop file
'            'should be installed on client machines
'            excelApp = New Excel.Application()

'            'create the task list on the first worksheet in the workbook
'            workBook = excelApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet)
'            ws = CType(workBook.Worksheets(1), Worksheet)
'        Catch
'            'remove the excel references: Excel, Microsoft.Office.Core, and VBIDE and re-add
'            'the COM reference Microsoft Excel 10.0 Type Library.
'            MessageBox.Show("An incompatible version of Microsoft Excel is intalled on your system.")
'            Return
'        End Try

'        ' Title
'        ws.Name = "Task Management"
'        ws.Cells(row, 1) = "Tasks as of " + Now.ToShortDateString()
'        r = CType(ws.Cells(row, 1), Range)
'        r.Font.Bold = True
'        row += 2

'        'create Headers
'        Dim dc As DataColumn
'        For Each dc In TasksData.Tables(0).Columns
'            Dim col As DataGridViewColumn
'            For Each col In TasksGrid.Columns
'                If col.Visible = True Then
'                    If col.Name = dc.ColumnName Then
'                        ws.Cells(row, cell) = col.HeaderText()
'                        ws.Columns(cell).autoFit()
'                        Exit For
'                    End If
'                End If
'                cell += 1
'            Next
'            cell = 1
'        Next
'        row += 1

'        'create rows
'        priorityHigh = 0
'        priorityNormal = 0
'        priorityLow = 0

'        'Dim myRow As DataRow
'        Dim i As Integer

'        For i = 0 To TasksDataView.Count - 1
'            For Each dc In TasksData.Tables(0).Columns
'                Dim col As DataGridViewColumn
'                For Each col In TasksGrid.Columns
'                    If col.Visible = True Then
'                        If col.Name = dc.ColumnName Then
'                            If TasksDataView.Item(i).Item(dc.ColumnName.ToString()).GetType() Is GetType(DateTime) Then
'                                ws.Cells(row, cell) = String.Format("{0:d}", TasksDataView.Item(i).Item(dc.ColumnName.ToString()))
'                            Else
'                                ws.Cells(row, cell) = TasksDataView.Item(i).Item(dc.ColumnName.ToString())
'                            End If
'                            If col.Name = "PriorityText" Then
'                                Select Case TasksDataView.Item(i).Item(dc.ColumnName.ToString())
'                                    Case "Major"
'                                        priorityHigh += 1
'                                    Case "Medium"
'                                        priorityNormal += 1
'                                    Case "Minor"
'                                        priorityLow += 1
'                                End Select
'                            End If
'                            ws.Columns(cell).autoFit()
'                            Exit For
'                        End If
'                    End If
'                    cell += 1
'                Next
'                cell = 1
'            Next
'            row += 1
'        Next

'        ' Priority Summary and Chart on Second Worksheet
'        ws = CType(workBook.Worksheets.Add(, ws), Worksheet)
'        ws.Name = "Priority Summary"

'        row = 1
'        ws.Cells(row, 1) = "Priority Summary"
'        r = CType(ws.Cells(row, 1), Range)
'        r.Font.Bold = True
'        row += 2
'        ws.Cells(row, 1) = "Major"
'        ws.Cells(row, 2) = priorityHigh.ToString
'        row += 1
'        ws.Cells(row, 1) = "Medium"
'        ws.Cells(row, 2) = priorityNormal.ToString
'        row += 1
'        ws.Cells(row, 1) = "Minor"
'        ws.Cells(row, 2) = priorityLow.ToString

'        ws.Columns(1).autoFit()
'        ws.Columns(2).autoFit()

'        ' Create the chart
'        r = ws.Range("A3", "B5")
'        r.Select()
'        c = ws.Parent.Charts.Add
'        With c
'            .ChartType = XlChartType.xl3DPieExploded
'            .SetSourceData(r, XlRowCol.xlColumns)
'            .Name = "Priority Summary Chart"
'            .HasTitle = True
'            .ChartTitle.Characters.Text = "Tasks by Priority"
'            .Location(Excel.XlChartLocation.xlLocationAsObject, ws.Name)
'        End With

'        ' Show(Excel)
'        excelApp.Sheets(1).Select()
'        excelApp.Visible = True
'    End Sub

'End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -