Ver Mensaje Individual
  #1 (permalink)  
Antiguo 20/05/2015, 07:22
wasauski81
 
Fecha de Ingreso: mayo-2015
Mensajes: 3
Antigüedad: 9 años
Puntos: 0
Gridview a Excel con fotos redimensionadas

Hola:

Quiero pasar una tabla (Gridview) que contiene fotos en el servidor a excel. Tengo todo ya programado el problema que tengo es que cuando le doy a exportar, me genera el excel pero con las fotos en el tamaño real de la celda, y no se ajusta la foto al tamaño de la celda...

No se que hago mal...

adjunto lo que hago:

Las fotos de la tabla:

<asp:TemplateField ItemStyle-Height = "100" ItemStyle-Width = "100" HeaderText = "IMAGE 2" ItemStyle-Wrap="True">
<ItemTemplate>
<asp:Image ID="ID" runat="server" AlternateText=""
ControlStyle-Height="100" ControlStyle-Width="100"
ImageUrl='<%# Eval("foto1")%>' />
</ItemTemplate>
</asp:TemplateField>


Boton exportar a excel:

Protected Sub ExportToExcel(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExport.Click, btnExport.Click
Response.Clear()
Response.Buffer = True
Response.AddHeader("content-disposition", "attachment;filename=RDs - " & Now & ".xls")
Response.Charset = ""
Response.ContentType = "application/vnd.ms-excel"
Using sw As New StringWriter()
Dim hw As New HtmlTextWriter(sw)
'To Export all pages

GridView1.AllowPaging = False


Me.llenartabla_para_exportar() ' este proceso hace la consulta para actualizar el gridview

GridView1.HeaderRow.BackColor = Color.White
For Each cell As TableCell In GridView1.HeaderRow.Cells
cell.BackColor = GridView1.HeaderStyle.BackColor
Next
For Each row As GridViewRow In GridView1.Rows
row.BackColor = Color.White
For Each cell As TableCell In row.Cells
If row.RowIndex Mod 2 = 0 Then
cell.BackColor = GridView1.AlternatingRowStyle.BackColor
Else
cell.BackColor = GridView1.RowStyle.BackColor
End If
Next
Next
GridView1.RenderControl(hw)
'style to format numbers to string
Dim style As String = "<style> .textmode { } </style>"


Response.Write(style)
Response.Output.Write(sw.ToString())
Response.Flush()
Response.[End]()

End Using
end sub

Muchas gracias de antemano!!!!