How to export to Excel data from a table (datatable) asp.net mvc 5

0

This is on my table I need to send to excel

This is a part of my view

<div class="panel panel-flat">
    <div class="panel-heading">
        <h5 class="panel-title">Tipo Planilla:<strong> @ViewBag.FrecuenciaPagoDescripcion</strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Agencia:<strong> @ViewBag.AgenciaDescripcion</strong> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Planilla Numero:<strong> @ViewBag.PlaNumero</strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Fecha Inicio:<strong> @ViewBag.PlaFechaInicio</strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Fecha Fin:<strong> @ViewBag.PlaFechaFin</strong>@*ALIMENTOS DE CORTES: Planilla de <strong>@ViewBag.TipoPlanillaDescripcion</strong>*@</h5>
        <div class="heading-elements">
            <ul class="icons-list">
                <li><a data-action="collapse"></a></li>
                <li><a data-action="reload"></a></li>
                <li><a data-action="close"></a></li>
            </ul>
        </div>
    </div>




        @*<table id="TblMercancias" class="table table-xxs datatable-responsive">*@
     <table id="TblMercancias" class="table table-xxs datatable-responsive" >
            <thead>
                <tr>
                    @*<th width="50%"><p style="white-space:nowrap"> Codigo Empleado</p></th>*@
                    @*<td style="font-size:larger;" class="TdValor center"> <span class="label   bg-danger label-block "> <strong>@TotalDeducciones</strong>  </span> </td>*@

                    <th style="text-align:center"><p style="white-space:nowrap;"> Codigo</p></th>
                    <th style="text-align:center"><p style="white-space:nowrap;"> Empleado</p></th>
                    <th style="text-align:center"><p style="white-space:nowrap;">Puesto</p></th>
                    <th style="text-align:center"><p style="white-space:nowrap;">Sueldo Base</p></th>
                    <th style="text-align:center"><p style="white-space:nowrap;">HE 25 PRO</p></th>

                    @*Encabezado de los Beneficios Frecuentes*@
                    @if (ViewBag.otrosBeneficiosLista != null)
                    {
                        foreach (var BeneficiosFrecuente in (IEnumerable<RecursosHumanos.Models.BeneficiosFrecuentesNombre>)ViewBag.BeneficiosFrecuentes)
                        {
                            foreach (var beneficiosSeleccionados in (List<string>)ViewBag.otrosBeneficiosLista)
                            {
                                if (BeneficiosFrecuente.DedDescripcion == beneficiosSeleccionados)
                                {
                                    <th style="text-align:center"><p style="white-space:nowrap;"> @beneficiosSeleccionados</p></th>
                                }
                            }
                        }
                    }

                    @*Encabezado de losBeneficios No Frecuentes*@
                    @if (ViewBag.otrosBeneficiosLista != null)
                    {
                        foreach (var BeneficiosNoFrecuente in (IEnumerable<RecursosHumanos.Models.BeneficiosNombre>)ViewBag.BeneficiosNoFrecuentes)
                        {
                            foreach (var beneficiosSeleccionados in (List<string>)ViewBag.otrosBeneficiosLista)
                            {
                                if (BeneficiosNoFrecuente.DedDescripcion == beneficiosSeleccionados)
                                {
                                    <th style="text-align:center"><p style="white-space:nowrap;"> @beneficiosSeleccionados</p></th>
                                }
                            }

                        }
                    }
                    <th><p style="white-space:nowrap;">Tot.Devengado</p></th>
                    <th><p style="white-space:nowrap;">IHSS</p></th>
                    <th><p style="white-space:nowrap;">RAP</p></th>

                    @*Encabezado de las Deducciones*@
                    @if (ViewBag.Deducciones != null)
                    {
                        foreach (var deduccionesFreNombre in (IEnumerable<RecursosHumanos.Models.DeduccionesFrecuentesNombre>)ViewBag.solicitud)
                        {
                            foreach (var Deduccion in (List<string>)ViewBag.Deducciones)
                            {
                                if (deduccionesFreNombre.DedDescripcion == Deduccion)
                                {
                                    <th style="text-align:center"><p style="white-space:nowrap;">@Deduccion</p></th>
                                }

                            }
                        }
                    }

                    @*Encabezado de las Deducciones*@
                    @if (ViewBag.Deducciones != null)
                    {
                        foreach (var Deducciones in (IEnumerable<RecursosHumanos.Models.DeduccionesNombre>)ViewBag.deduccionesN)
                        {
                            foreach (var Deduccion in (List<string>)ViewBag.Deducciones)
                            {
                                if (Deducciones.DedDescripcion == Deduccion)
                                {
                                    <th style="text-align:center"><p style="white-space:nowrap;">@Deduccion</p></th>
                                }
                            }
                        }
                    }
                    <th style="text-align:center"><p style="white-space:nowrap;">Tot.Deducciones</p></th>
                    <th style="text-align:center"><p style="white-space:nowrap;">Pago Neto</p></th>
                </tr>
            </thead>
    
asked by Marco Eufragio 15.11.2018 в 21:25
source

1 answer

1

If that control is a Bootstrap datatable, an exporter brings it to different formats.

$(document).ready(function() {
    $('#example').DataTable( {
        dom: 'Bfrtip',
        buttons: [
            'copy', 'csv', 'excel', 'pdf', 'print'
        ]
    } );
} );

Here the documentation. link

    
answered by 16.11.2018 / 11:41
source