none
Content in .apsx to excel VB NET RRS feed

  • Question

  • I have a page which loads a table, wanted to export to excel how can I do?

    <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="RelRegepaCap.aspx.vb"
        Inherits="IHInternetService_Relatorios.RelRegepaCap" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script>
            function Esconde() {
                document.all("cboStatus").style.display = "none";
            }
    
           
        </script>
    </head>
    <body>
        <form id="Form1" method="post" runat="server" onkeypress="if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById('cmdContinuar').click();return false;}} else {return true};">
        <div id="dvValidaRelClientes" class="Erro">
        </div>
        <table class="caixa_home" id="Table4" cellspacing="0" cellpadding="3" width="640px"
            border="0">
            <tr>
                <td>
                    <table width="100%" cellspacing="0" cellpadding="4" border="0" class="linha_caixa_home">
                        <tbody>
                            <tr class="fundo_titulo_tabelas_internas">
                                <td>
                                    Buscar por:
                                </td>
                            </tr>
                            <tr class="fundo_caixa_home">
                                <td>
                                    <table width="100%" cellspacing="1" cellpadding="3" border="0" class="TiraBorda">
                                        <tbody>
                                            <tr class="fundo_caixa_home">
                                                <td class="Texto2">
                                                    Tipo de Produtos:
                                                </td>
                                                <td class="fundo_cinza Texto_1">
                                                    <asp:CheckBox ID="CheckBoxPM" runat="server" Text="M" OnCheckedChanged="FiltraProduto" />
                                                    <asp:CheckBox ID="CheckBoxPU" runat="server" Text="U" OnCheckedChanged="FiltraProduto" />
                                                </td>
                                            </tr>
                                            <tr class="fundo_caixa_home">
                                                <td class="Texto2">
                                                    Produtos
                                                </td>
                                                <td class="fundo_cinza Texto_1">
                                                    <asp:ListBox ID="cboProdutos" runat="server" CssClass="InputP" DataValueField="PRODUTO"
                                                        DataTextField="NOMNEGOCIACAO" Height="54px" SelectionMode="Single" Width="349px">
                                                    </asp:ListBox>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="Texto2">
                                                    CPF/CNPJ do cliente
                                                </td>
                                                <td class="fundo_cinza Texto_1">
                                                    <asp:TextBox ID="txtCPF" CssClass="InputP" Width="140px" runat="server" MaxLength="14"></asp:TextBox>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="Texto2">
                                                    Título
                                                </td>
                                                <td class="fundo_cinza Texto_1">
                                                    <asp:TextBox ID="txtTitulo" CssClass="InputP" Width="140px" runat="server" MaxLength="11"></asp:TextBox>
                                                </td>
                                            </tr>
                                        </tbody>
                                    </table>
                                    <table width="100%" align="center">
                                        <tr>
                                            <td width="25%">
                                            </td>
                                            <td align="center">
                                                <asp:Button ID="cmdContinuar" CssClass="botao_formulario" runat="server" Text="Consultar">
                                                </asp:Button>
                                            </td>
                                            <td align="center">
                                            </td>
                                            <td width="25%">
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Panel ID="pnlRelatorio" runat="server" Visible="<%#rptRegepa.Items.Count>0%>">
                        <asp:Repeater ID="rptRegepa" runat="server">
                            <HeaderTemplate>
                                <table id="resultado" cellspacing="0" cellpadding="4" width="100%" border="0">
                                    <tr>
                                        <td>
                                            <table class="linha_caixa_home" cellspacing="0" cellpadding="4" width="100%" border="0">
                                                <tr class="fundo_cinza Texto2">
                                                    <td>
                                                         Nº do Título
                                                    </td>
                                                    <td width="20%">
                                                        Série
                                                    </td>
                                                    <td>
                                                        Proposta
                                                    </td>
                                                    <td>
                                                       Nome Cliente
                                                    </td>
                                                    <td>
                                                        Cpf/Cnpj Cliente
                                                    </td>
                                                    <td>
                                                        Conta Corrente
                                                    </td>
                                                    <td>
                                                        Cód. Produto
                                                    </td>
                                                    <td>
                                                        Nome Produto
                                                    </td>
                                                    <td>
                                                        Status
                                                    </td>
                                                    <td>
                                                        Vlr. Mensalidade
                                                    </td>
                                                    <td>
                                                        Última Parcela Paga
                                                    </td>
                                                    <td>
                                                        Data Último Pagamento
                                                    </td>
                                                    <td>
                                                        Vlr. Reserva
                                                    </td>
                                                </tr>
                                                <tr class="fundo_caixa_home">
                                                    <td colspan="13" style="height: 3px;">
                                                    </td>
                                                </tr>
                            </HeaderTemplate>
                            <ItemTemplate>
                                <tr id="trClienteSorte" runat="server">
                                    <td class="Texto_1">
                                        <%#Container.DataItem("TITULO")%>
                                    </td>
                                    <td class="Texto_1">
                                        <%#Container.DataItem("SERIE")%>
                                    </td>
                                    <td class="Texto_1">
                                         <%#Container.DataItem("PROPOSTA")%>
                                    </td>
                                    <td class="Texto_1">
                                         <%#Container.DataItem("NOME_CLIENTE")%>
                                    </td>
                                    <td class="Texto_1">
                                         <%#Container.DataItem("CPF_CNPJ_CLIENTE")%>
                                    </td>
                                    <td class="Texto_1">
                                        <%#Container.DataItem("CONTA_CORRENTE")%>
                                    </td>
                                    <td class="Texto_1">
                                        <%#Container.DataItem("PRODUTO")%>
                                    </td>
                                    <td class="Texto_1">
                                        <%#Container.DataItem("NOMNEGOCIACAO")%>
                                    </td>
                                     <td class="Texto_1">
                                        <%#Container.DataItem("STATUS_TITULO")%>
                                    </td>
                                     <td class="Texto_1">
                                        <%#Databinder.Eval(Container.DataItem,"VALOR_MENSALIDADE","{0:N2}")%>
                                    </td>
                                    <td class="Texto_1">
                                        <%#Container.DataItem("ULTIMA_PARCELA_PAGA")%>
                                    </td>
                                    <td class="Texto_1">
                                       <%#Databinder.Eval(Container.DataItem,"DT_ULTIMO_PAGAMENTO","{0:dd/MM/yyyy}")%>
                                    </td>
                                     <td class="Texto_1">
                                        <%#DataBinder.Eval(Container.DataItem, "VALOR_RESERVA_CLIENTE", "{0:N2}")%>
                                    </td>
    
                                    
                                </tr>
                            </ItemTemplate>
                            <FooterTemplate>
                                </TABLE> </TD> </TR> </TABLE>
                            </FooterTemplate>
                        </asp:Repeater>
                        </br>
                        <table id="exportar" cellspacing="0" cellpadding="0" width="100%" align="center"
                            border="0" runat="server" visible="<%#rptRegepa.Items.Count>0%>">
                            <tr>
                                <td width="30%">
                                </td>
                                <td align="center" width="40%">
                                    <asp:Button ID="cmdExportarExcel" CssClass="botao_formulario" runat="server" Text="Exportar Excel">
                                    </asp:Button>
                                </td>
                                <td width="30%">
                                </td>
                            </tr>
                        </table>
                    </asp:Panel>
                </td>
            </tr>
        </table>
        </form>
    </body>
    </html>
    

    Imports IcatuHartford.ClienteOnline.Collections
    Imports IcatuHartford.SiteServicos.Facade
    Imports IcatuHartford.Util
    Imports System.Configuration.ConfigurationSettings
    Imports System.IO
    Imports IcatuHartford.ClienteOnline.Lumis
    Imports IcatuHartford.IService
    Imports IcatuHartford.IService.Transactions
    Imports IcatuHartford.ClienteOnline.Controller
    
    Public Class RelRegepaCap
        Inherits IcatuHartford.Web.UI.Pagina
    
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If Not Page.IsPostBack Then
                PopularControles()
            End If
        End Sub
    
        Private Sub PopularControles()
            txtCPF.Attributes.Add("onkeypress", "MascInteiro();")
            txtTitulo.Attributes.Add("onkeypress", "MascInteiro();")
    
            Dim oRelFacade As New RelRegepaCapFacade
            Dim Dt As New DataTable
    
            With Me.cboProdutos
                .DataSource = oRelFacade.GetProduto(Me.CacheApp.Item(VariaveisContexto.Veiculo.ToString()))
                .DataBind()
            End With
        End Sub
        Public Sub FiltraProduto(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBoxPU.CheckedChanged
           
    
        End Sub
    
        Protected Sub cmdContinuar_Click(sender As Object, e As EventArgs) Handles cmdContinuar.Click
            Dim RelRegepaCapFac As New RelRegepaCapFacade
            Dim dt As DataTable
            Dim cod_veiculo As String
            Dim cpfcnjp As String
            Dim titulo As String
            Dim useruniqueID As Guid
            Dim CodProduto As String
            Dim TpProduto As String
    
    
            useruniqueID = New Guid(Me.Usuario.Identity.Id)
            cod_veiculo = Me.CacheApp.Item(VariaveisContexto.Veiculo.ToString())
            cpfcnjp = txtCPF.Text
            titulo = txtTitulo.Text
            CodProduto = cboProdutos.SelectedValue
    
            If CheckBoxPM.Checked Then
                TpProduto = "M"
            ElseIf CheckBoxPU.Checked Then
                TpProduto = "U"
            Else
                TpProduto = String.Empty
            End If
    
            Try
                With Me.rptRegepa
                    .DataSource = RelRegepaCapFac.GetRelRegepa(cod_veiculo, cpfcnjp, titulo, useruniqueID, CodProduto, TpProduto)
                    .DataBind()
                End With
    
            Finally
                RelRegepaCapFac = Nothing
            End Try
        End Sub
    
        Protected Sub cmdExportarExcel_Click(sender As Object, e As EventArgs) Handles cmdExportarExcel.Click
            GeraRelatorioExcel()
    
        End Sub
        Private Sub GeraRelatorioExcel()
       
        End Sub
    
    
    End Class


    • Moved by Youjun Tang Thursday, July 2, 2015 2:04 AM more related to the suggested forum
    Monday, June 29, 2015 8:01 PM

All replies

  • You know that an ASP.Net application is running on the Server. 

    The only thing you do on the Client is handling the webbrowser and that cannot (really) reach the client (beside Cookies and a new HTML5 replacement for that, but which is in fact the same).

    Therefore if you want to save the Excel file on your server, than you can use this kind of code otherwise. Find another solution.


    Success
    Cor

    Monday, June 29, 2015 8:54 PM
  • Hello,

    Consider asking your question over at the ASP.NET forum.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my webpage under my profile but do not reply to forum questions.

    Monday, June 29, 2015 10:00 PM