C # - Reading Excel

0

I was able to read an excel file, but when displaying console the information does not get any spaces, how can I make room in the middle? kkkk

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Data;usingSystem.Data.OleDb;namespaceLeitura_Excel{classProgram{staticvoidMain(string[]args){OleDbConnectionconexao=newOleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0.0;
                                                            Data Source=C:\Users\re029391\Documents\Resource It\Documentos\Cargos.xlsx;
                                                            Extended Properties='Excel 12.0 Xml;HDR=YES'");

            OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM [Planilha1$]", conexao);
            DataSet ds = new DataSet();

            try
            {
                conexao.Open();
                adapter.Fill(ds);
                Console.WriteLine("".PadRight(50, '-'));
                Console.WriteLine("Nome".PadRight(35) + "Cargo".PadLeft(15));
                Console.WriteLine("".PadRight(50, '-'));
                foreach (DataRow linha in ds.Tables[0].Rows)
                {
                    Console.WriteLine(linha["Nome"].ToString() + linha["Cargo"].ToString().PadRight(50));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Erro ao acessar os dados: " + ex.Message);
            }
            finally
            {
                conexao.Close();
            }
            Console.WriteLine("".PadRight(50, '-'));
            Console.WriteLine("Feito!");
            Console.ReadKey();
        }
    }
}
    
asked by anonymous 06.11.2018 / 17:16

0 answers