Professional Documents
Culture Documents
JheysonMatta ExportarTodo VB
JheysonMatta ExportarTodo VB
Imports
Imports
Imports
Imports
System.Data
System.Data.SqlClient
System.Data.OleDb
System.IO
exApp = Nothing
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Error al exportar a Excel"
)
Return False
End Try
Return True
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.E
ventArgs) Handles Button1.Click
Call GridAExcel(DataGridView1)
End Sub
------------------------------------------------------------------------------------------------------------------------
Imports PdfSharp
Imports PdfSharp.Pdf
Imports PdfSharp.Drawing
Imports PdfSharp.Drawing.Layout
Public Class JheysonMatta_PDF
Private
Private
Private
Private
maTamao() As Integer
miTamao As Integer = 0
miPaginas As Integer = 0
miPaginaActual As Integer
FuenteLinea.GetHeight(Grafico)
String = Directory.GetCurrentDirectory() & "\Prueba.pdf"
Integer = 0
Integer
Process.Start(Archivo)
Catch ex As Exception
MessageBox.Show(ex.Message, "lP_Imprimir", MessageBoxButtons.OKCance
l, MessageBoxIcon.Information)
End Try
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.
Click
lP_ImprimirDGV(Me.DataGridView1)
End Sub
End Class
Public Class LapizPDF
Private mGrafico As XGraphics
Public Property Grafico() As XGraphics
Get
Return mGrafico
End Get
Set(ByVal Value As XGraphics)
mGrafico = Value
End Set
End Property
Public Sub New(ByVal objGrafico As XGraphics)
mGrafico = objGrafico
End Sub
Public Sub CuadroRedondo(ByVal PosX As Integer, ByVal PosY As Integer, ByVal
Ancho As Integer, ByVal Alto As Integer, ByVal Grosor As Integer, Optional ByVa
l Sombra As Boolean = False)
Dim Cuadro As XRect = New XRect(PosX, PosY, Ancho, Alto)
Dim Lapiz As XPen = New XPen(XColor.FromArgb(0, 0, 0), Grosor)
Dim Elipse As XSize
Elipse.Height = 10
Elipse.Width = 10
If Sombra = True Then
mGrafico.DrawRoundedRectangle(Lapiz, XBrushes.Beige, Cuadro, Elipse)
Else
mGrafico.DrawRoundedRectangle(Lapiz, Cuadro, Elipse)
End If
End Sub
Public Sub CuadroRecto(ByVal PosX As Integer, ByVal PosY As Integer, ByVal A
ncho As Integer, ByVal Alto As Integer, ByVal Grosor As Integer, Optional ByVal
Sombra As Boolean = False)
Dim Cuadro As XRect = New XRect(PosX, PosY, Ancho, Alto)
Dim Lapiz As XPen = New XPen(XColor.FromArgb(0, 0, 0), Grosor)
If Sombra = True Then
mGrafico.DrawRectangle(Lapiz, XBrushes.Beige, Cuadro)
Else
mGrafico.DrawRectangle(Lapiz, Cuadro)
End If
End Sub
Public Sub LineaH(ByVal PosX1 As Integer, ByVal PosY1 As Integer, ByVal Anch
o As Integer, ByVal Grosor As Integer)
Dim Lapiz As XPen = New XPen(XColor.FromArgb(0, 0, 0), Grosor)
Imports System.Data
Imports System.Data.SqlClient
Imports Microsoft.Office.Interop.Word
Public Class JheysonMatta_Word
Dim StrCn = "Data Source=.;Initial Catalog=Northwind;Integrated Security=Tru
e"
Dim Cn As New SqlConnection(StrCn)
Dim Da As New SqlDataAdapter
Dim Cmd As New SqlCommand
Dim Dt As DataTable
Private Sub Form_Load(ByVal sender As System.Object, ByVal e As System.Event
Args) Handles MyBase.Load
With Cmd
.CommandType = CommandType.Text
.CommandText = "SELECT CustomerID, CompanyName,ContactTitle,Address,
City,Region,PostalCode FROM Customers"
.Connection = Cn
End With
Da.SelectCommand = Cmd
Dt = New DataTable
Da.Fill(Dt)
DataGridView1.DataSource = Dt
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.E
ventArgs) Handles Button1.Click
Call GrillaAWord(DataGridView1)
End Sub
Public Function GrillaAWord(ByVal Grilla As DataGridView)
Dim Word As Application
Dim Doc As Document
Dim Table As Table
Dim Rng As Range
Dim Prf1 As Paragraph
Dim Prf2 As Paragraph
Dim Prf3 As Paragraph
Word = CreateObject("Word.Application")
Word.Visible = False
Doc = Word.Documents.Add
Prf1 = Doc.Content.Paragraphs.Add
Prf1.Range.Text = "Jheyson Matta - Exportando DataGridView1 a Word"
Prf1.Range.Font.Color = WdColor.wdColorBlue
Prf1.Range.Font.Bold = True
Prf1.Format.SpaceAfter = 24
Prf1.Range.InsertParagraphAfter()
Prf2 = Doc.Content.Paragraphs.Add(Doc.Bookmarks.Item("\endofdoc").Range)
Prf2.Range.Text = "DESCRIPCION"
Prf2.Range.Font.Color = WdColor.wdColorBlack
Prf2.Format.SpaceAfter = 6
Prf2.Range.InsertParagraphAfter()
Prf3 = Doc.Content.Paragraphs.Add(Doc.Bookmarks.Item("\endofdoc").Range)
Prf3.Range.Text = "Programa hecho a pedido de Suscriptores de mi canal."
& _
" Suscribete: https://www.youtube.com/user/jheysonmatta:"
Prf3.Range.Font.Bold = False
Prf3.Format.SpaceAfter = 24
Prf3.Range.InsertParagraphAfter()
Dim NCol As Integer = Grilla.ColumnCount
Dim NRow As Integer = Grilla.RowCount
'alternativo
ProgressBar1.Maximum = NRow - 1
Table = Doc.Tables.Add(Doc.Bookmarks.Item("\endofdoc").Range, Grilla.Row
Count, Grilla.ColumnCount)
'Agregando Los Campos De La Grilla
For i As Integer = 1 To NCol
Table.Cell(1, i).Range.Text = Grilla.Columns(i - 1).Name.ToString
Next
'Agregando Los Registros A La Tabla
For Fila As Integer = 0 To NRow - 2
For Col As Integer = 0 To NCol - 1
If Grilla.Rows(Fila).Cells(Col).Value IsNot DBNull.Value Then
Table.Cell(Fila + 2, Col + 1).Range.Text = Grilla.Rows(Fila)
.Cells(Col).Value
End If
Next
'Incremento
ProgressBar1.Increment(1)
Next
'Negrita y Kursiva Para Los Nombres De Los Campos
Table.Rows.Item(1).Range.Font.Bold = True
Table.Rows.Item(1).Range.Font.Italic = True
'Boder De La Tabla
Table.Borders.InsideLineStyle = WdLineStyle.wdLineStyleDot
Table.Borders.OutsideLineStyle = WdLineStyle.wdLineStyleDot
Table.Borders.InsideColor = WdColor.wdColorBlue
Rng = Doc.Bookmarks.Item("\endofdoc").Range
Rng.InsertParagraphAfter()
Rng.InsertAfter("ATTE: Jheyson Matta Per.")
MessageBox.Show("Exportacion Completado.. ")
Word.Visible = True
End Function
End Class