示例#1
0
        public static Ent_EncabezadoExcel Encabezado(string ruta)
        {
            Ent_EncabezadoExcel EncabezadoExcel = new Ent_EncabezadoExcel();

            // Declaro las variables necesarias
            Microsoft.Office.Interop.Excel._Application xlApp;
            Microsoft.Office.Interop.Excel._Workbook    xlLibro;
            Microsoft.Office.Interop.Excel._Worksheet   xlHoja1;
            Microsoft.Office.Interop.Excel.Sheets       xlHojas;
            //asigno la ruta dónde se encuentra el archivo
            string fileName = ruta;

            //inicializo la variable xlApp (referente a la aplicación)
            xlApp = new Microsoft.Office.Interop.Excel.Application();
            //Muestra la aplicación Excel si está en true
            xlApp.Visible = false;
            //Abrimos el libro a leer (documento excel)
            xlLibro = xlApp.Workbooks.Open(fileName, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);

            try
            {
                //  Asignamos las hojas
                xlHojas = xlLibro.Sheets;
                //Asignamos la hoja con la que queremos trabajar:
                //xlHoja1 = (Microsoft.Office.Interop.Excel._Worksheet)xlHojas["Hoja 1"];
                xlHoja1 = xlLibro.ActiveSheet;     //(Microsoft.Office.Interop.Excel. ._Worksheet)xlHojas["Hoja 1"];

                //recorremos las celdas que queremos
                string cliente    = (string)xlHoja1.get_Range("B" + 6, Missing.Value).Text;
                string orden      = (string)xlHoja1.get_Range("B" + 5, Missing.Value).Text;
                string lugar      = (string)xlHoja1.get_Range("B" + 8, Missing.Value).Text;
                string reporte    = (string)xlHoja1.get_Range("B" + 9, Missing.Value).Text;
                string recepcion  = (string)xlHoja1.get_Range("C" + 8, Missing.Value).Text;
                string referencia = (string)xlHoja1.get_Range("B" + 10, Missing.Value).Text;
                string muestras   = (string)xlHoja1.get_Range("B" + 7, Missing.Value).Text;
                EncabezadoExcel.Cliente    = cliente;
                EncabezadoExcel.Orden      = orden;
                EncabezadoExcel.Lugar      = lugar;
                EncabezadoExcel.Reporte    = reporte;
                EncabezadoExcel.Recepcion  = recepcion;
                EncabezadoExcel.Referencia = referencia;
                EncabezadoExcel.Muestras   = muestras;
            }
            finally
            {
                //Cerrar el Libro
                xlLibro.Close(false, Missing.Value, Missing.Value);
                //Cerrar la Aplicación
                xlApp.Quit();
            }
            return(EncabezadoExcel);
        }
示例#2
0
        private void btnProcesar_Click(object sender, EventArgs e)
        {
            this.StsLabel1.Text        = "Llenando Encabezado";
            this.StsProgressBar1.Value = 25;
            #region Llenando el Encabezado
            if (this.TxbPath.Text.Length != 0)
            {
                Ent_EncabezadoExcel Encabezado = LeerExcel.Encabezado(this.TxbPath.Text);
                this.TxbCliente.Text    = Encabezado.Cliente;
                this.TxbOrden.Text      = Encabezado.Orden;
                this.TxbLugar.Text      = Encabezado.Lugar;
                this.TxbMuestras.Text   = Encabezado.Muestras;
                this.TxbReferencia.Text = Encabezado.Referencia;
                this.TxbReporte.Text    = Encabezado.Reporte;
                this.TxbRecepcion.Text  = Encabezado.Recepcion;
            }
            #endregion


            this.StsLabel1.Text        = "Llenando Tabla Principal";
            this.StsProgressBar1.Value = 50;
            #region Llenando el dataGridView Principal
            if (this.TxbPath.Text.Length != 0)
            {
                DataSet DS;
                DS = LeerExcel.DatosGQ15(this.TxbPath.Text);
                dataGridView1.DataSource = DS.Tables[0];
                dataGridView1.AutoResizeColumns();

                foreach (DataGridViewRow row in dataGridView1.Rows)
                {
                    row.Cells[0].Value = true;
                }
                this.chbMarcar.Checked = true;

                int I = 0;
                foreach (DataGridViewColumn Column in dataGridView1.Columns)
                {
                    if (I == 0)
                    {
                        Column.ReadOnly = false;
                    }
                    else
                    {
                        Column.ReadOnly = true;
                    }
                    I += 1;
                }
            }
            else
            {
                MessageBox.Show("Seleccione un archivo");
            }
            #endregion


            this.StsLabel1.Text        = "Llenando Tabla Resumen";
            this.StsProgressBar1.Value = 75;
            #region LLenado de DataGrid Auxiliar
            DataTable dt = new DataTable();
            dt.Columns.Add("Id");
            dt.Columns.Add("IdPadre");
            dt.Columns.Add("Sello");
            dt.Columns.Add("Tenor");
            DataRow Row     = dt.NewRow();
            string  IdLim   = "";
            string  LimSupP = "";
            string  G_TM    = "";
            int     Id      = 1;

            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                string SelloP = Convert.ToString(row.Cells[2].Value);
                if (SelloP.IndexOf("a") + SelloP.IndexOf("b") + SelloP.IndexOf("c") == -3)
                {
                    IdLim   = Convert.ToString(row.Cells[1].Value);
                    LimSupP = Convert.ToString(row.Cells[2].Value);
                    G_TM    = Convert.ToString(row.Cells[5].Value);

                    Row["Id"]      = Id;
                    Row["IdPadre"] = IdLim;
                    Row["Sello"]   = LimSupP;
                    Row["Tenor"]   = G_TM;
                    dt.Rows.Add(Row);
                    Row = dt.NewRow();
                    Id++;
                }
            }

            DataSet DataS = new DataSet();
            DataS.Tables.Add(dt);
            dataGridView2.DataSource = DataS.Tables[0];
            dataGridView2.AutoResizeColumns();

            try
            {
                foreach (DataGridViewRow Row2 in dataGridView2.Rows)
                {
                    string         SelloConsulta = Convert.ToString(Row2.Cells[2].Value);
                    SqlParameter[] Parametros    = new SqlParameter[1];
                    Parametros[0] = new SqlParameter("@Sello", SelloConsulta);

                    ConsultaEntidades Entidad = new ConsultaEntidades();
                    Ent_MinaSello     Reader  = new Ent_MinaSello();
                    Reader = Entidad.MinaSello("ConsultarSelloSGS", Parametros);

                    if (Reader.Consecutivo == 0)
                    {
                        dataGridView2.Rows[Row2.Index].DefaultCellStyle.BackColor = Color.SkyBlue;
                    }
                }
            }
            catch (Exception Ext)
            {
                MessageBox.Show(Ext.Message);
            }


            #endregion


            for (int i = 0; i < 1000; i++)
            {
                i += 1;
            }
            this.StsProgressBar1.Value = 100;
            this.StsLabel1.Text        = "Listo";
            this.StsProgressBar1.Value = 0;
        }