捕获正确的行索引

时间:2018-05-14 16:59:38

标签: c# asp.net

如何从Excel电子表格中捕获行索引?在我的代码中,我确定int i变量得到值4,并添加i ++,在日志中传递变量,以便它跳过标题,从1到5并从下一个捕获索引在我的treading方法中使用foreach,我正在使用DataRow。有人可以帮我一把吗?

我的鳕鱼:

private System.Threading.Tasks.Task TableProcessing(IEnumerable<DataRow> dataparam, int i, User UserLogged)
{            
    i = 4;
    Action<object> processing = (data) =>
    {
        /*if (NHibernate.Context.ThreadStaticSessionContext.HasBind(NhibernateHelper.SessionFactory.))*/
        NHibernate.Context.ThreadStaticSessionContext.Bind(NhibernateHelper.HelpThreading().OpenSession());     
        foreach (var line in (IEnumerable<DataRow>)data)
        {                   
            i++;   
            List<Process> listProcessExisting = new List<Process>();
            Process process = null;
            Interested interested = new Interested();
            //search for the process by the previous or current judicial number
            if (!line.ItemArray[1].ToString().Equals(""))
                process = aplProcess.consultPerNProcessER(line.ItemArray[1].ToString());
            if (process == null)
            {
                if (!line.ItemArray[2].ToString().Equals(""))
                    process = aplProcess.consultPerNProcessER(linha.ItemArray[2].ToString());
            }

            //search the interested by cpf / cnpj, cpf / cnpj is an identification of the interested party.
            if (line.ItemArray[7].ToString().Length == 14)
                interested = aplaplInterested.ConsultPerCPF(AuxiliarCPF_CNPJ.DeformationCPF(line.ItemArray[7].ToString()));

            if (line.ItemArray[7].ToString().Length == 18)
                interested = aplInterested.ConsultPerCPF(HelpCPF_CNPJ.DeformationCNPJ(line.ItemArray[7].ToString()));
            if (process != null)
            {
                //if the process is not null I search all procinter related to it.
                List<ProcessInterested> listprocessinterested = aplProcessInterested.consultPerIdProcess(process.Code);
                if (listprocessinterested.Exists(o => o.Interested == interested))
                    log.Append("The interested "+ process.Interested.Name +", entered in the line "+ (i + 1) +" was added back to the process "+ process.NumberProcessjudicial + " <br>");

                setProcessInterested(process, interested, line, i);
            }
            else
            {
                //New Process - 6.3
                process = new Process();
                process.Interested = interested;
            }
        }
    }
}    

1 个答案:

答案 0 :(得分:0)

我能够解决我的问题如下:

   protected void importar_Click(object sender, EventArgs e)
            {

     DataTable Dados = new DataTable();

    Dados = DadosExcel(Excel);

    Dados.Columns.Add("indice", typeof(int));

                            int i = 1;
                            foreach (DataRow linha in Dados.Rows)
                            {
                               linha["index"] = i;
                                i++; 
                            }
            }