Public Class clsExcel 'Public Sub sbExportaDataReader(ByVal SQL As String) ' Dim clCpx As New clsComplejo() ' Dim clCpxAva As New clsComplejo() ' Dim vntRenglon As Object ' Dim Exl As Excel.Application ' Dim Wst As Excel.Worksheet ' Dim drConsulta As SqlClient.SqlDataReader ' Dim i, j, k As Integer ' Dim A As Object ' Dim Z As Object ' Dim Progreso As New ExcProgreso() ' Dim liRegistros As Integer ' drConsulta = clCpx.fdDataReader(SQL) ' liRegistros = clCpxAva.fiCuantosRegistros(SQL) ' Exl = CreateObject("Excel.Application") ' Exl.Workbooks.Add() ' Wst = Exl.Worksheets(1) ' If liRegistros > 65536 Then ' MsgBox("Total de registros excede el número permitido", vbInformation) ' Exit Sub ' End If ' Progreso.pbrAvance.Maximum = liRegistros ' Progreso.Text = "Exportando a Excel" ' Progreso.Show() ' For k = 0 To drConsulta.FieldCount - 1 ' Wst.Cells(1, k + 1).Value = drConsulta.GetName(k) ' Wst.Cells(1, k + 1).Interior.Color = RGB(210, 210, 210) ' Next ' i = 1 ' While drConsulta.Read ' For j = 0 To drConsulta.FieldCount - 1 ' vntRenglon = drConsulta.GetValue(j) ' Wst.Cells(i + 1, j + 1).Value = vntRenglon ' Next ' Progreso.pbrAvance.Value = i ' Progreso.Refresh() ' ' Progreso.lblAvance.Text = CInt((i * 100) / liRegistros) & " %" ' i = i + 1 ' End While ' A = Wst.Cells(1, 1) ' Z = Wst.Cells(i + 1, j + 1) ' Wst.Columns("A:Z").EntireColumn.AutoFit() ' 'Wst.Range(A, Z).AutoFormat(Excel.XlRangeAutoFormat.xlRangeAutoFormatList2) ' Exl.Visible = True ' Exl = Nothing ' Progreso.Close() 'End Sub End Class