private void MenuArquivoExcelXML_Click(object sender, EventArgs e) { AbrirTamplates.Title = "Buscar Arquivo XML"; AbrirTamplates.InitialDirectory = DirArquivo; AbrirTamplates.FileName = string.Empty; AbrirTamplates.DefaultExt = ".xml"; AbrirTamplates.Filter = "Arquivos XML|*.xml|*.XML|"; AbrirTamplates.RestoreDirectory = true; if (AbrirTamplates.ShowDialog() == System.Windows.Forms.DialogResult.OK) { try { using (DataSet Ds = new DataSet()) { Ds.ReadXml(AbrirTamplates.FileName); if (Ds != null && Ds.Tables[0].Rows.Count > 0) { CarregaGridView(Ds.Tables[0]); return; } else { Mensagens.Alerta("Não foi possível carregar nenhum registro apartir do XML informado. Por favor selecione outro arquivo."); } } } catch (Exception ex) { Mensagens.Erro(string.Format("Não foi possível carregar o arquivo XML. {0}", ex.Message)); } } }
private void MenuArquivoExcelXLSX_Click(object sender, EventArgs e) { AbrirTamplates.Title = "Buscar Arquivo Excel"; //AbrirTamplates.InitialDirectory = DirArquivo; //AbrirTamplates.FileName = string.Empty; AbrirTamplates.DefaultExt = ".xlsx"; AbrirTamplates.Filter = "Arquivos Excel|*.xlsx"; AbrirTamplates.RestoreDirectory = true; if (AbrirTamplates.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string NomePlan = RetornaNomePlanilhaSelecionado(); if (string.IsNullOrEmpty(NomePlan)) { return; } try { ImportarArquivos xlsx = new ImportarArquivos(); //using (DataTable dt = xlsx.ImportarXLSX("C:\\Users\\MARQUES\\Desktop\\Pasta1.xlsx", "plan1")) using (DataTable dt = xlsx.ImportarXLSX(AbrirTamplates.FileName, NomePlan)) { if (dt != null && dt.Rows.Count > 0) { CarregaGridView(dt); return; } else { Mensagens.Alerta("Não foi possível carregar nenhum registro apartir do .xlsx informado. Por favor selecione outro arquivo."); } } } catch (Exception ex) { Mensagens.Erro(string.Format("Não foi possível carregar o arquivo: {0}", ex.Message)); } } }
private void MenuArquivoExcelCSV_Click(object sender, EventArgs e) { AbrirTamplates.Title = "Buscar Arquivo Excel"; //AbrirTamplates.InitialDirectory = DirArquivo; //AbrirTamplates.FileName = string.Empty; AbrirTamplates.DefaultExt = ".csv"; AbrirTamplates.Filter = "Arquivos Excel|*.csv"; AbrirTamplates.RestoreDirectory = true; if (AbrirTamplates.ShowDialog() == System.Windows.Forms.DialogResult.OK) { //string NomePlan = RetornaNomePlanilhaSelecionado(); //if (string.IsNullOrEmpty(NomePlan)) return; try { ImportarArquivos csv = new ImportarArquivos(); using (DataTable dt = csv.ImportarSCV(AbrirTamplates.FileName)) { if (dt != null && dt.Rows.Count > 0) { CarregaGridView(dt); return; } else { Mensagens.Alerta("Não foi possível carregar nenhum registro apartir do .csv informado. Por favor selecione outro arquivo."); } } } catch (Exception ex) { Mensagens.Erro(string.Format("Não foi possível carregar o arquivo: {0}", ex.Message)); } } }