Exemple #1
0
        public string verificarExcel()
        {
            try
            {
                List <FormatoExcelMaestro> datosIngresados = new List <FormatoExcelMaestro>();
                if (Request != null)
                {
                    HttpPostedFileBase file = Request.Files["file-0"];
                    if ((file != null) && (file.ContentLength > 0) && !string.IsNullOrEmpty(file.FileName))
                    {
                        string fileName        = file.FileName;
                        string fileContentType = file.ContentType;
                        byte[] fileBytes       = new byte[file.ContentLength];
                        var    data            = file.InputStream.Read(fileBytes, 0, Convert.ToInt32(file.ContentLength));
                        using (var package = new ExcelPackage(file.InputStream))
                        {
                            var currentSheet = package.Workbook.Worksheets;
                            var workSheet    = currentSheet.First();
                            var noOfCol      = workSheet.Dimension.End.Column;
                            var noOfRow      = workSheet.Dimension.End.Row;

                            for (int rowIterator = 2; rowIterator <= noOfRow; rowIterator++)
                            {
                                FormatoExcelMaestro datos = new FormatoExcelMaestro();
                                datos.codigo             = workSheet.Cells[rowIterator, 1].Value.ToString();
                                datos.codigoBarra        = workSheet.Cells[rowIterator, 2].Value.ToString();
                                datos.codigoBarraInterno = workSheet.Cells[rowIterator, 3].Value.ToString();
                                datos.descripcion        = workSheet.Cells[rowIterator, 4].Value.ToString();
                                datos.stockMinimo        = double.Parse(workSheet.Cells[rowIterator, 5].Value.ToString());
                                datos.stockMaximo        = double.Parse(workSheet.Cells[rowIterator, 6].Value.ToString());
                                datos.bodega             = workSheet.Cells[rowIterator, 7].Value.ToString();

                                datosIngresados.Add(datos);
                            }
                        }
                    }
                }
                return("true");
            }
            catch (Exception e)
            {
                return(e.Message);
            }
        }
Exemple #2
0
        public ActionResult ActualizarExcel(FormCollection formCollection)
        {
            List <FormatoExcelMaestro> datosIngresados = new List <FormatoExcelMaestro>();

            if (Request != null)
            {
                HttpPostedFileBase file = Request.Files["UploadedFile"];
                if ((file != null) && (file.ContentLength > 0) && !string.IsNullOrEmpty(file.FileName))
                {
                    string fileName        = file.FileName;
                    string fileContentType = file.ContentType;
                    byte[] fileBytes       = new byte[file.ContentLength];
                    var    data            = file.InputStream.Read(fileBytes, 0, Convert.ToInt32(file.ContentLength));
                    using (var package = new ExcelPackage(file.InputStream))
                    {
                        var currentSheet = package.Workbook.Worksheets;
                        var workSheet    = currentSheet.First();
                        var noOfCol      = workSheet.Dimension.End.Column;
                        var noOfRow      = workSheet.Dimension.End.Row;

                        for (int rowIterator = 2; rowIterator <= noOfRow; rowIterator++)
                        {
                            FormatoExcelMaestro datos = new FormatoExcelMaestro();
                            datos.codigo             = workSheet.Cells[rowIterator, 1].Value.ToString();
                            datos.codigoBarra        = workSheet.Cells[rowIterator, 2].Value.ToString();
                            datos.codigoBarraInterno = workSheet.Cells[rowIterator, 3].Value.ToString();
                            datos.descripcion        = workSheet.Cells[rowIterator, 4].Value.ToString();
                            datos.stockMinimo        = double.Parse(workSheet.Cells[rowIterator, 5].Value.ToString());
                            datos.stockMaximo        = double.Parse(workSheet.Cells[rowIterator, 6].Value.ToString());
                            datos.bodega             = workSheet.Cells[rowIterator, 7].Value.ToString();

                            datosIngresados.Add(datos);
                        }
                    }
                    ViewBag.Users = datosIngresados;
                }
            }
            FormatoExcelMaestro.agregar(datosIngresados);

            return(RedirectToAction("Index"));
        }