Пример #1
0
        private void LerExcel(string arquivo, string planilha, string sqlCustom = "")
        {
            string sql = string.Empty;

            if (sqlCustom == "")
            {
                if (planilha == "Efetivo$")
                {
                    sql = Efetivo.Sql();
                }
                else if (planilha == "Gestão$")
                {
                    sql = Gestao.Sql();
                }
                else if (planilha == "'Absenteísmo até 15 dias$'")
                {
                    sql = AbsenteismoAteQuinzeDias.Sql();
                }
                else if (planilha == "'Absent + 15 dias e até 6 meses $'")
                {
                    sql = AbsenteismoMaisQuinzeDiasAteSeisMeses.Sql();
                }
                else if (planilha == "'Absent + de  6 meses$'")
                {
                    sql = AbsenteismoMaisSeisMeses.Sql();
                }
                else if (planilha == "'Acidentes Próprio$'")
                {
                    sql = AcidenteProprio.Sql();
                }
                else if (planilha == "'Acidentes Terceiros$'")
                {
                    sql = AcidenteTerceiro.Sql();
                }
                else if (planilha != "")
                {
                    sql = "select * from [" + planilha + "] ";
                }
                else
                {
                    return;
                }
            }
            else
            {
                sql = sqlCustom;
            }

            try
            {
                var result = new DaoGenerico().GetDados(sql, arquivo);

                dgvDados.DataSource = null;
                dgvDados.DataSource = result;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Erro ao acessar os dados: " + ex.Message);
            }
        }
Пример #2
0
        private String[] GetExcelSheetNames(string arquivo)
        {
            try
            {
                var dt = new DaoGenerico().GetPlanilhas(arquivo);

                if (dt == null)
                {
                    return(null);
                }

                String[] excelSheets = new String[dt.Rows.Count];
                int      i           = 0;

                // Adiciona os nomes na array
                foreach (DataRow row in dt.Rows)
                {
                    if (!row["TABLE_NAME"].ToString().Contains("Print_Titles") &&
                        !row["TABLE_NAME"].ToString().Contains("Print_Area"))
                    {
                        excelSheets[i] = row["TABLE_NAME"].ToString();
                        i++;
                    }
                }

                // Loop através de todas as folhas se você quiser também..
                //for (int j = 0; j < excelSheets.Length; j++)
                //{
                //  // Consultar cada folha de excel
                //}

                return(excelSheets);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }