Public Class ExportTest
    Private Sub ExportTest_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.供应商TableAdapter.Fill(Me.NorthwindDataSet.供应商)


        '构建表格二的内容，表格一为上边的自动取数
        Dim i As Integer
        Dim j As Integer
        Dim mycol As DataGridViewColumn
        Dim myrow As DataGridViewRow
        Dim rows As Integer
        Dim cols As Integer

        cols = 2 '2
        rows = 105
        D2.ColumnCount = cols
        D2.RowCount = rows
        '加一列按钮列
        For i = 0 To cols - 1
            mycol = D2.Columns(i)
            mycol.HeaderText = "第" + CStr(i + 1) + "列"
        Next
        Dim myco2 As New DataGridViewButtonColumn()
        myco2.HeaderText = "按钮列"
        myco2.Visible = True
        myco2.DefaultCellStyle.BackColor = Color.DarkGray
        D2.Columns.Add(myco2)

        D2.Rows(2).Cells(2).Style.ForeColor = Color.Blue
        D2.Rows(2).Cells(2).Style.Font = New Font("华文行楷", 12, FontStyle.Bold Or FontStyle.Strikeout Or FontStyle.Underline)
        cols = 3



        For i = 0 To rows - 1
            myrow = D2.Rows(i)
            For j = 0 To cols - 1
                myrow.Cells(j).Value = "第" + CStr(i + 1) + "行 第" + CStr(j + 1) + "列"
            Next

        Next
        D2.Columns(2).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        D2.Columns(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight

        D2.Rows(0).Cells(0).Value = "表格2"

        Dim mycolumn As New DataGridViewCheckBoxColumn()

        'D2.Columns(2).CellTemplate
        Dim myco As New DataGridViewImageColumn()
        myco.HeaderText = "图片框"
        myco.Visible = True
        myco.ImageLayout = DataGridViewImageCellLayout.Zoom
        D2.Columns.Add(myco)
        D2.Rows(0).Cells(3).Value = My.Resources.mybmp
        D2.Rows(3).Cells(3).Value = My.Resources.myico


        mycolumn.HeaderText = "复选框"
        mycolumn.Visible = True
        mycolumn.TrueValue = "YES"
        mycolumn.FalseValue = "NO"
        D2.Columns.Add(mycolumn)
        D2.Rows(0).Cells(4).Value = "YES"
        D2.Rows(1).Cells(4).Value = "NO"

       

    End Sub



   



    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim myexport As New VBprinter.ExportDGV
        myexport.Title = TextBox1.Text
        myexport.TitleFont = TextBox1.Font
        myexport.OpenFile = CheckBox1.Checked
        If CheckBox2.Checked = True Then
            myexport.PaperWidth = 0
        End If
        If RadioButton1.Checked = True Then
            '导出excel
            myexport.ExportDGV(d1, VBprinter.ExportDGV.ExportDGVType.Excel)
        ElseIf RadioButton2.Checked = True Then
            'PDF
            myexport.ExportDGV(d1, VBprinter.ExportDGV.ExportDGVType.PDF)
        ElseIf RadioButton3.Checked Then
            'RTF
            myexport.ExportDGV(d1, VBprinter.ExportDGV.ExportDGVType.RTF)
        ElseIf RadioButton4.Checked Then
            'HTML
            myexport.ExportDGV(d1, VBprinter.ExportDGV.ExportDGVType.HTML)
        Else
            '自己选择
            myexport.ExportDGV(d1)
        End If

        myexport.Dispose()
        myexport = Nothing

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        FontDialog1.Font = TextBox1.Font
        FontDialog1.ShowColor = False
        If FontDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            TextBox1.Font = FontDialog1.Font
        End If
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim myexport As New VBprinter.ExportDGV
        myexport.Title = TextBox1.Text
        myexport.TitleFont = TextBox1.Font
        myexport.OpenFile = CheckBox1.Checked
        If CheckBox2.Checked = True Then
            myexport.PaperWidth = 0
        End If
        If RadioButton1.Checked = True Then
            '导出excel
            myexport.ExportDGV(D2, VBprinter.ExportDGV.ExportDGVType.Excel)
        ElseIf RadioButton2.Checked = True Then
            'PDF
            myexport.ExportDGV(D2, VBprinter.ExportDGV.ExportDGVType.PDF)
        ElseIf RadioButton3.Checked Then
            'RTF
            myexport.ExportDGV(D2, VBprinter.ExportDGV.ExportDGVType.RTF)
        ElseIf RadioButton4.Checked Then
            'HTML
            myexport.ExportDGV(D2, VBprinter.ExportDGV.ExportDGVType.HTML)
        Else
            '自己选择
            myexport.ExportDGV(D2)
        End If
        myexport.Dispose()
        myexport = Nothing
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        d1.MergeCell(2, 4, 1, 3)
        d1.MergeCell(5, 5, 3, 6)
        d1.MergeCell(7, 9, 2, 2)
        d1.RefreshMergeSetting()
    End Sub
End Class