2
Good morning guys, I’m making an excel converter to txt and a doubt arose, I was trying to make an algorithm in which it detects the column title and returns error if the column had the same title, but, how to make it identify only the title?
In this algorithm he only compares the column and row and returns the same column and row error.
for (int i = 0; i < dsPlan1.Tables[0].Columns.Count; i++) //todo: dispara a contagem da quantidade de tabelas
{
try
{
if (!TestaCampos(dsPlan1.Tables[0].Rows[0][i].ToString()))
{
try
{
if (dsPlan1.Tables[0].Rows[0][i].ToString() != "" )
{
cmps.Add(dsPlan1.Tables[0].Rows[0][i].ToString());
}
else
{
//erro.SetErro(38);
throw new Exception();
}
}
catch (Exception)
{
string txt = null;
i++; //Moacir 28062017 - soma 1 no contador para igualar a coluna do excel para visualização do usuário
txt += "Coluna " + dsPlan1.Tables[0].Columns.IndexOf(dsPlan.Tables[0].Columns[i].ColumnName);
txt += " com nome vazio no arquivo! Favor verificar!";
MessageBox.Show(txt, "", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
}
else
{
throw new Exception();
}
}
catch
{
string txt = null;
txt += "Coluna " + dgvMostrar.Rows[0].Cells[i].Value.ToString();
txt += " em duplicidade no arquivo! Favor verificar!";
MessageBox.Show(txt, "", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
}