Example #1
0
        private void hojas_SelectedIndexChanged(object sender, EventArgs e)
        {
            bool nullrow = false;

            row  = 0;
            Hoja = Hojas[hojas.SelectedIndex];
            //ya tengo abierto el archivo de exel
            //ahora intento estraer los registro de la hoja
            while (!nullrow)
            {
                nullrow = true;
                row++;
                FilaXLS obj = new FilaXLS();
                for (int col = 0; col <= 100; col++)
                {
                    CColumna cc = new CColumna();
                    string   cell;
                    char     cy = ' ';
                    char     cx = ((char)(65 + col)).ToString()[0];
                    if (cx > 'Z')
                    {
                        cy = (char)(64 + (int)col / (int)26);
                        cx = (char)((int)cx - (int)'Z' + 64);
                    }
                    cell  = cy.ToString().Trim() + cx.ToString();
                    cell += row;
                    try
                    {
                        cc.Columna = cell;
                        cc.x       = cx.ToString();
                        cc.y       = cy.ToString();
                        cell       = (string)Hoja.get_Range(cell, cell).Text;
                    }
                    catch (System.Exception)
                    {
                        break;
                    }
                    if (cell != "")
                    {
                        try
                        {
                            cc.Nombre = cell;
                            ListaCamposOrigen.Items.Add(cc);
                            obj.v[col] = cell;
                            nullrow    = false;
                        }
                        catch (Exception)
                        {
                            obj.v[col - 1] = "";
                        }
                    }
                    else
                    {
                        return;
                    }
                }
                //if (!nullrow)
                //{
                //    ListaCeldas.Items.Add(cell);
                //}
                //nullrow = false;
            }
        }
Example #2
0
        private void LeerLinea()
        {
            bool nullrow = true;

            row++;
            FilaXLS obj = new FilaXLS();
            //creo el comando para subir el campo a la base de datos
            string s = "";
            string s1 = "insert into " + TTablaDestino.Text + "(";
            int    i, n;

            n = ListaCamposDestino2.Items.Count;
            bool primero = true;

            s       = s + ") values(";
            primero = true;
            bool hayDatos = false;

            //recorre todos los campos
            for (int col = 0; col < ListaCamposOrigen2.Items.Count; col++)
            {
                Objetos.CParametro obj2 = (Objetos.CParametro)ListaCamposDestino2.Items[col];
                if (primero == true)
                {
                    primero = false;
                }
                else
                {
                    s1 = s1 + ",";
                    s  = s + ",";
                }
                //Objetos.CParametro obj2 = (Objetos.CParametro)ListaCamposDestino2.Items[col];
                s1 = s1 + obj2.nombre;
                //lectura del registro de excel
                CColumna cc = (CColumna)ListaCamposOrigen2.Items[col];
                string   cell;
                char     cy = ' ';
                char     cx = ((char)(65 + col)).ToString()[0];
                if (cx > 'Z')
                {
                    cy = (char)(64 + (int)col / (int)26);
                    cx = (char)((int)cx - (int)'Z' + 64);
                }
                cell  = cy.ToString().Trim() + cx.ToString();
                cell += row;
                try
                {
                    cc.Columna = cell;
                    if (Hoja.get_Range(cell, cell).Text != null)
                    {
                        cell = (string)Hoja.get_Range(cell, cell).Text;
                    }
                    else
                    {
                        cell = "";
                    }
                }
                catch (System.Exception)
                {
                    break;
                }
                if (cell != "")
                {
                    try
                    {
                        cc.Nombre  = cell;
                        obj.v[col] = cell;
                        nullrow    = false;
                    }
                    catch (Exception)
                    {
                        obj.v[col - 1] = "";
                    }
                }
                //termino de agregar los datos del campo de la consulta
                if (obj.v[col] == null)
                {
                    obj.v[col] = "";
                }
                if (obj.v[col].Length > obj2.Logitud && obj2.Logitud >= 0)
                {
                    s = s + "\'" + obj.v[col].Substring(0, obj2.Logitud).Replace('\'', ' ') + "\'";
                }
                else
                {
                    s = s + "\'" + obj.v[col].Replace('\'', ' ') + "\'";
                }
                if (obj.v[col] != "")
                {
                    hayDatos = true;
                }
            }
            if (!nullrow)
            {
                //aqui tengo el registro de exel
                s = s1 + s + ")";
                if (hayDatos == false)
                {
                    //timer1.Enabled = false;
                    status                = 2;
                    row                   = Comandos.Count;
                    BProgreso.Progreso    = 0;
                    BProgreso.ValorMaximo = row;
                    xlLibro.Close(false, Missing.Value, Missing.Value);
                    xlApp.Quit();
                    return;
                }
                else
                {
                    try
                    {
                        BProgreso.Texto = Comandos.Count + " Registros leídos";//row.ToString() + " Registros leídos";
                        Comandos.Add(s);
                    }
                    catch (System.Exception ex)
                    {
                        Errores = Errores + "\n" + ex;;
                    }
                }
            }
            else
            {
                status             = 2;
                row                = Comandos.Count;
                BProgreso.Progreso = 0;
                if (row > 0)
                {
                    BProgreso.ValorMaximo = row;
                }
                xlLibro.Close(false, Missing.Value, Missing.Value);
                xlApp.Quit();
            }
            nullrow = false;
        }