This commit is contained in:
Antonio Gonzalez
2020-09-17 15:10:46 -07:00
parent 2d53fdb089
commit 6fde7b5c45
3 changed files with 178 additions and 156 deletions

View File

@@ -100,93 +100,7 @@ Partial Class Ventas_AuxiliarCliente
Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
End Sub
Public Sub ExportToExcelGTest(Gv As GridView, NombreArchivoXLSx As String, Optional Titulo As String = "Reporte", Optional Usuario As Usuario = Nothing)
Dim sw As New StringWriter()
Dim htw As New HtmlTextWriter(sw)
Gv.RenderControl(htw)
GemBox.Spreadsheet.SpreadsheetInfo.SetLicense("ESWN-4QFD-26JF-1SZ8")
Dim excel As GemBox.Spreadsheet.ExcelFile
Dim options = GemBox.Spreadsheet.LoadOptions.HtmlDefault
Using htmlStream = New MemoryStream(options.Encoding.GetBytes(sw.ToString()))
excel = GemBox.Spreadsheet.ExcelFile.Load(htmlStream, options)
If Usuario IsNot Nothing Then
Dim worksheet = excel.Worksheets(0)
Dim num As Integer = worksheet.Rows.Count
If num > 128 Then num = 128
Dim columnCount = worksheet.CalculateMaxUsedColumns()
'If columnCount > 1 Then
' For i As Integer = 1 To columnCount - 1
' worksheet.Columns(i).AutoFit(1, worksheet.Rows(1), worksheet.Rows(num - 1))
' Next
'End If
worksheet.Rows.InsertEmpty(0, 7)
Dim Imagen As New System.IO.FileInfo(String.Format("{0}/Logo.png", Usuario.Empresa.Ruta))
Dim logouri = String.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", HttpContext.Current.Request.Url.Scheme, HttpContext.Current.Request.Url.Host, HttpContext.Current.Request.Url.Port, Usuario.CveEmpresa)
If Imagen.Exists Then
worksheet.Pictures.Add(logouri.ToString(), "A1", "B4")
End If
Dim celdasConTexto = worksheet.GetUsedCellRange(True)
celdasConTexto.Style.Font.Name = "Calibri Light"
Dim RangoNombreEmpresa = worksheet.Cells.GetSubrangeAbsolute(1, celdasConTexto.FirstColumnIndex, 1, celdasConTexto.LastColumnIndex)
RangoNombreEmpresa.Merged = True
RangoNombreEmpresa.Value = Usuario.Empresa.Empresa
RangoNombreEmpresa.Style.Font.Size = 18 * 20
RangoNombreEmpresa.Style.Font.Name = "Calibri Light"
RangoNombreEmpresa.Style.HorizontalAlignment = GemBox.Spreadsheet.HorizontalAlignmentStyle.Center
RangoNombreEmpresa.Style.VerticalAlignment = GemBox.Spreadsheet.VerticalAlignmentStyle.Center
Dim RangoTitulo = worksheet.Cells.GetSubrangeAbsolute(3, celdasConTexto.FirstColumnIndex, 3, celdasConTexto.LastColumnIndex)
RangoTitulo.Merged = True
RangoTitulo.Value = Titulo
RangoTitulo.Style.Font.Size = 20 * 20
RangoTitulo.Style.Font.Name = "Calibri Light"
RangoTitulo.Style.HorizontalAlignment = GemBox.Spreadsheet.HorizontalAlignmentStyle.Center
RangoTitulo.Style.VerticalAlignment = GemBox.Spreadsheet.VerticalAlignmentStyle.Center
Dim FiltroCliente = worksheet.Cells.GetSubrangeAbsolute(5, celdasConTexto.FirstColumnIndex, 5, celdasConTexto.LastColumnIndex)
FiltroCliente.Merged = True
FiltroCliente.Value = String.Format("Cliente: {0} Fecha Inicio: {1} Fecha Fin: {2} Opción: {3}", DdlClientes.SelectedText, txtFechaI.Text, txtFechaF.Text, DdlOpcion.SelectedItem.Text)
FiltroCliente.Style.Font.Size = 12 * 20
FiltroCliente.Style.Font.Name = "Calibri Light"
FiltroCliente.Style.HorizontalAlignment = GemBox.Spreadsheet.HorizontalAlignmentStyle.Left
FiltroCliente.Style.VerticalAlignment = GemBox.Spreadsheet.VerticalAlignmentStyle.Center
For i = celdasConTexto.FirstColumnIndex To celdasConTexto.LastColumnIndex
worksheet.Rows(7).Cells(i).Style.Font.Size = 12 * 20
worksheet.Rows(7).Cells(i).Style.HorizontalAlignment = GemBox.Spreadsheet.HorizontalAlignmentStyle.Center
worksheet.Rows(7).Cells(i).Style.VerticalAlignment = GemBox.Spreadsheet.VerticalAlignmentStyle.Center
worksheet.Rows(7).Cells(i).Style.FillPattern.SetPattern(GemBox.Spreadsheet.FillPatternStyle.Solid, GemBox.Spreadsheet.SpreadsheetColor.FromArgb(75, 119, 190), GemBox.Spreadsheet.SpreadsheetColor.FromArgb(255, 255, 255))
worksheet.Rows(7).Cells(i).Style.Font.Color = GemBox.Spreadsheet.SpreadsheetColor.FromArgb(255, 255, 255)
'If i > 0 Then
' Try
' worksheet.Columns(i).AutoFit(1)
' Catch ex As Exception
' End Try
'End If
Next
Dim IndexEndTable As Integer = Gv.Rows.Count + 9
worksheet.Rows(IndexEndTable).Cells(0).Value = "Usuario Imprimió:"
worksheet.Rows(IndexEndTable + 1).Cells(0).Value = Usuario.Nombre
worksheet.Rows(IndexEndTable).Cells(4).Value = "Fecha Impresión: "
worksheet.Rows(IndexEndTable + 1).Cells(4).Value = DateTime.Now.ToString()
worksheet.Rows(IndexEndTable).Cells(8).Value = "Impreso en SIG"
End If
End Using
htw.Dispose()
excel.Save(HttpContext.Current.Response, NombreArchivoXLSx)
ExportToExcelGembox(Gv, NombreArchivoXLSx, Usuario, txtFechaI.Text, txtFechaF.Text, Titulo, "", 1)
End Sub
Protected Sub GvAuxCliente_RowDataBound(sender As Object, e As GridViewRowEventArgs)