16/02/2010, 03:27
|
| | Fecha de Ingreso: julio-2009
Mensajes: 60
Antigüedad: 15 años, 5 meses Puntos: 0 | |
Respuesta: Exportar a Excel o a Word Yo lo unico que te puedo decir es que contruyo un excel a partir de un dataset.
Aqui te dejo el boton que me ocntruye el excel.Un saludo
Protected Sub ImageButton_Excel_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)
Try
Dim i, j As Integer
Dim ls_color1, ls_color2, ls_color As String
Dim li_color As Integer = 1
Dim dataset_grid As New DataSet
Dim directorio_base As String
Dim li_contador_productos As Integer
Dim cliente As String
Dim periodo As Integer
cliente = Me.txt_cliente_antiguo_id.Text
periodo = convertir_periodo_anno(Me.cmb_periodos.SelectedIte m.Text)
periodo = Integer.Parse(periodo)
Session("codigo_distribuidor") = cliente
Session("periodo") = periodo
dataset_grid = clase_gestionDimSQL.Devuelve_clientes_porcentaje(S ession("Usuario_red"), "Mantenimiento_actual2.aspx", Session("periodo"), Session("codigo_distribuidor"))
directorio_base = System.AppDomain.CurrentDomain.BaseDirectory()
Dim ofile As File
Dim oDir As DirectoryInfo
oDir = New DirectoryInfo(directorio_base & ConfigurationManager.AppSettings("\TEMPORAL\"))
If File.Exists(directorio_base & ConfigurationManager.AppSettings("\TEMPORAL\listad o_prioridades_distribuidores.xls")) Then
File.Delete(directorio_base & ConfigurationManager.AppSettings("\TEMPORAL\listad o_prioridades_distribuidores.xls"))
End If
li_contador_productos = dataset_grid.Tables(0).Rows.Count
If li_contador_productos > 0 Then
ls_color1 = "LightSteelBlue"
ls_color2 = "Lavender"
Response.Clear()
Response.AddHeader("Content-Disposition", "attachment; filename=" & directorio_base & "\TEMPORAL\listado_prioridades_distribuidores.xls" )
Response.ContentType = "application/vnd.ms-excel"
Response.Write("<table border='0' id='ctl00_ContentPlaceHolder1_GridView_productos'> ")
Response.Write("<tr>")
Response.Write("<td style='background-color: #6666ff; font-weight: bold; font-size: 14px;text-align: center; vertical-align: middle; width: 220px; border-top-style: solid; border-right-style: solid; border-left-style: solid; border-bottom-style: solid;'>Distribuidor</td><td style='background-color: #6666ff; font-weight: bold; font-size: 14px;text-align: center; vertical-align: middle; width: 100px; border-top-style: solid; border-right-style: solid; border-left-style: solid; border-bottom-style: solid;'>Periodo</td><td style='background-color: #6666ff; font-weight: bold; font-size: 14px;text-align: center; vertical-align: middle; width: 100px; border-top-style: solid; border-right-style: solid; border-left-style: solid; border-bottom-style: solid;'>Prioridad</td>")
Response.Write("</tr>")
For i = 0 To dataset_grid.Tables(0).Rows.Count - 1
If li_color = 1 Then
ls_color = ls_color1
li_color = 2
Else
ls_color = ls_color2
li_color = 1
End If
Response.Write(" <tr>")
For j = 0 To dataset_grid.Tables(0).Columns.Count - 1
If j = 0 Or j = 2 Or j = 3 Then
Response.Write(" <td style='background-color:" & ls_color & ";text-align: center;vertical-align: middle;border-right-style: solid; border-left-style: solid; border-bottom-style: solid;'>" & Server.HtmlEncode(dataset_grid.Tables(0).Rows(i).I tem(j).ToString) & "</td>")
Else
Response.Write(" <td style='background-color:" & ls_color & "; text-align: center;vertical-align: middle;border-right-style: solid; border-left-style: solid; border-bottom-style: solid;'>" & Server.HtmlEncode(dataset_grid.Tables(0).Rows(i).I tem(j).ToString) & "</td>")
End If
Next
Next
Response.Write("</table>")
Response.End()
End If
Catch ex As Exception
End Try
End Sub |