Dim xlWorkBook As Excel.Workbook = Nothing
Dim xlWorkBooks As Excel.Workbooks = Nothing
Dim xlWorkSheet As Excel.Worksheet
Dim xlWorkSheets As Excel.Worksheets = Nothing
Dim xlRange As Excel.Range = Nothing
Dim FileSend As String
Dim str As New Bitacora.Subject
Dim Msg As String
Try
'Creating a new object of the excel application objectxlApp = New Excel.Application
'Hiding the excel application
xlApp.Visible = False
'Hiding all the alert messages occurring during the process
xlApp.DisplayAlerts = False
'Adding a collection of workbooks to the excel object
xlWorkBook = CType(xlApp.Workbooks.Add(), Excel.Workbook)'Saving the workbook as a normal workbook format
xlWorkBook.SaveAs(FileName, Excel.XlFileFormat.xlWorkbookNormal)
'Gettin the path
FileSend = xlWorkBook.Path & "\" & FileName'Getting the collection of workbooks in an object
xlWorkBooks = xlApp.Workbooks
'Get the reference to the first sheet in the workbook collection in a variable
xlWorkSheet = CType(xlWorkBooks(1).Worksheets.Item(1), Excel.Worksheet)
'The name of the worksheet
xlWorkSheet.Name = "Pendientes"'Get the cells collection of the sheet in a variable to write the data
xlRange = xlWorkSheet.Cells
'Calling the function to write the datatable data in the cells of the first sheet
dt = fun.PendientesGenerados(datos.nAgente, datos.nAgenteBck, Fecha)
str.PGenerados = dt.Rows.Count
WriteData(dt, xlRange)
'Setting the width of the specified range of cells so as to absolutely fit the written data
xlWorkSheet.Range("A1", "Z1").EntireColumn.AutoFit()
'2nd Sheet
xlWorkSheet = xlWorkBook.Worksheets.Add
xlWorkSheet.Name = "TicketsActualizados"
xlRange = xlWorkSheet.Cells
dt = fun.TicketsActualizados(datos.nAgente, datos.nAgenteBck, Fecha)
str.TModificados = dt.Rows.Count
WriteData(dt, xlRange)
xlWorkSheet.Range("A1", "Z1").EntireColumn.AutoFit()
'3rd Sheet
xlWorkSheet = xlWorkBook.Worksheets.AddxlWorkSheet.Name = "TicketsRecibidos"
xlRange = xlWorkSheet.Cells
dt = fun.TicketsRecibidos(datos.nAgente, datos.nAgenteBck, Fecha)
str.TRecibidos = dt.Rows.Count
WriteData(dt, xlRange)
xlWorkSheet.Range("A1", "Z1").EntireColumn.AutoFit()
'4th Sheet
xlWorkSheet = xlWorkBook.Worksheets.AddxlWorkSheet.Name = "TicketsGenerados"
xlRange = xlWorkSheet.Cells
dt = fun.TicketsGenerados(datos.nAgente, datos.nAgenteBck, Fecha)
str.TGenerados = dt.Rows.Count
WriteData(dt, xlRange)
xlWorkSheet.Range("A1", "Z1").EntireColumn.AutoFit()
'5th Sheet
xlWorkSheet = xlWorkBook.Worksheets.Add
xlWorkSheet.Name = "TransaccionesIngresadas"
xlRange = xlWorkSheet.Cells
dt = fun.TransaccionesIngresadas(datos.nAgente, datos.nAgenteBck, Fecha)
str.TIngresadas = dt.Rows.Count
WriteData(dt, xlRange)
xlWorkSheet.Range("A1", "Z1").EntireColumn.AutoFit()
'6th Sheet
xlWorkSheet = xlWorkBook.Worksheets.Add
xlWorkSheet.Name = "ClientesContactados"
xlRange = xlWorkSheet.Cells
dt = fun.ClientesContactados(datos.nAgente, datos.nAgenteBck, Fecha)
str.CContactados = dt.Rows.Count
WriteData(dt, xlRange)
xlWorkSheet.Range("A1", "Z1").EntireColumn.AutoFit()
'Delete Sheets
For Each sheet As Excel.Worksheet In xlWorkBook.Sheets
If sheet.Name = "Sheet2" Or sheet.Name = "Sheet3" Then
sheet.Delete()
End If
Next
xlWorkSheet.SaveAs(FileName)
xlWorkBook.Close()
xlWorkBook = Nothing
No comments:
Post a Comment