Example #1
0
        public void ExportarArchivoExcel()
        {
            DataTable dtExcel       = new DataTable();
            string    nombreArchivo = "HolaMundo.xlsx";
            List <Entidades.Factura.Factura> ListFactura = new List <Entidades.Factura.Factura>();

            try
            {
                Negocio.Factura.Factura negFactura = new Negocio.Factura.Factura();
                ListFactura = negFactura.GetFactura();


                dtExcel.Columns.Add("Id");
                dtExcel.Columns.Add("Nombre");
                dtExcel.Columns.Add("Descripcion");

                foreach (var fac in ListFactura)
                {
                    dtExcel.Rows.Add(fac.Id, fac.Concepto, fac.Monto);
                }


                var book = new ExcelQueryFactory("C:\\Users\\k697344\\Documents\\HolaMundo.xlsx");

                var rows = book.Worksheet("HolaMundo").ToList();

                //DataTable ds = ExcelLibrary.DataSetHelper.CreateDataTable("C:\\Users\\k697344\\Documents\\HolaMundo.xlsx", "HolaMundo");

                using (XLWorkbook wb = new XLWorkbook())
                {
                    wb.Worksheets.Add(dtExcel, "HolaMundo");

                    var work = wb.Worksheet("HolaMundo");

                    work.Cells("A1:A3").Style.Fill.BackgroundColor = XLColor.Yellow;
                    work.Cell(17, 1).Value = "Analisis";

                    Response.ClearContent();
                    Response.Buffer      = true;
                    Response.Charset     = "";
                    Response.ContentType = "application/vnd.ms-excel";
                    Response.AddHeader("content-disposition", "attachment; filename=" + nombreArchivo);

                    using (MemoryStream MyMemoryStream = new MemoryStream())
                    {
                        wb.SaveAs(MyMemoryStream);
                        MyMemoryStream.WriteTo(Response.OutputStream);
                        Response.Flush();
                        Response.End();
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
Example #2
0
        public JsonResult GuardarFactura()
        {
            string resultado = "";

            //LA CONEXION A NEGOCIO
            Negocio.Factura.Factura negFactura = new Negocio.Factura.Factura();

            //LLENAR OBJETO FACTURA
            Entidades.Factura.Factura Factura = new Entidades.Factura.Factura();
            Factura.Concepto  = "Factura nueva";
            Factura.Monto     = 5000;
            Factura.RFC       = "SOSOSM8777878";
            Factura.Direccion = "NORTE 45 455 B";

            //LLENAR OBJETOS DETALLE FACTURA
            List <Entidades.Factura.DetalleFactura> ListDetalleFactura = new List <Entidades.Factura.DetalleFactura>();

            Entidades.Factura.DetalleFactura DetalleFactura = new Entidades.Factura.DetalleFactura();

            DetalleFactura.Producto = "Pantalon";
            DetalleFactura.Cantidad = 2;
            DetalleFactura.Importe  = 100;
            DetalleFactura.SubTotal = 90;
            DetalleFactura.Iva      = 10;
            DetalleFactura.Total    = 200;
            ListDetalleFactura.Add(DetalleFactura);

            DetalleFactura          = new Entidades.Factura.DetalleFactura();
            DetalleFactura.Producto = "Falda";
            DetalleFactura.Cantidad = 3;
            DetalleFactura.Importe  = 150;
            DetalleFactura.SubTotal = 400;
            DetalleFactura.Iva      = 50;
            DetalleFactura.Total    = 450;
            ListDetalleFactura.Add(DetalleFactura);

            DetalleFactura          = new Entidades.Factura.DetalleFactura();
            DetalleFactura.Producto = "Blusa";
            DetalleFactura.Cantidad = 1;
            DetalleFactura.Importe  = 50;
            DetalleFactura.SubTotal = 45;
            DetalleFactura.Iva      = 5;
            DetalleFactura.Total    = 50;
            ListDetalleFactura.Add(DetalleFactura);


            resultado = negFactura.GuardarFactura(Factura, ListDetalleFactura);

            return(Json(resultado, JsonRequestBehavior.AllowGet));
        }