Entradas

Mostrando las entradas etiquetadas como datagridview

Exportar a excel en vb.net

Bueno, lo que realizaremos a continuacion es exportar un DataGridView a excel, les explico. Primero se crea un proceso para realizar esta accion, el cual leera toda la informacion contenida en el Grid, y lo cuadara en una tabla: Dim drow As DataRow Dim col As Integer Dim r As String Dim dtable, dtable2 As New DataTable Dim fila As Integer dtable.Clear() dtable.Columns.Clear() 'Se crea un ciclo para los encabezados For col = 0 To dgw.Columns.Count - 1 If dgw.Columns(col).Visible = True Then r = dgw.Columns(col).HeaderText.ToString dtable.Columns.Add(New DataColumn(r, GetType(String))) End If Next drow = Nothing col = 0 'Llenamos los registrod del table For fila = 0 To dgw.Rows.Count - 1 drow = dtable.NewRow() For col = 0 To dgw.Columns.Count - 1 If dgw.Columns(col).Visible = True Then drow(dgw.Columns(col).HeaderText.ToString) = CStr(dgw.Item(col, fila).Value) End If Next dtable.Rows.Add(drow) Next Try Dim iExp As New Funciones iExp.TablaExcel(dtable) Catch ex As Exception MsgBo...

Copiar al protapapeles el contenido de un DGView en vb.net

Buen dia: Esta es mi primer entrada en el blogg espero les sea de utilidad. el codigo es el siguiente y se hizo con vb 2005: Dim Datos As String = Nothing Dim i, k As Integer Try Me.Cursor = Cursors.WaitCursor For k = 0 To dgwArchivo.ColumnCount - 1 Datos = CStr(Datos & dgwArchivo.Columns(k).Name & vbTab) Next Datos = CStr(Datos & vbNewLine) k = 0 'Recorremos todos los datos de la columna en la que hicimos click For i = 0 To dgwArchivo.Rows.Count - 1 For k = 0 To dgwArchivo.ColumnCount - 1 Datos = CStr(Datos & CStr(dgwArchivo.Item(k, i).Value) & vbTab) Next Datos = Datos & vbNewLine Next ' limpiamos el portapapeles Clipboard.Clear() 'Copiamos los datos del Datagrid al Clipboard Clipboard.SetText(Datos) Me.Cursor = Cursors.Default MsgBox("Archivo compiado con exito", MsgBoxStyle.Information, Application.ProductName) Me.Close() Catch ex As Exception MsgBox("Error al copiar el archivo: " & e.ToString, MsgBoxStyle.Critical,applica...