Robson Amaral

Robson Amaral

  • NA
  • 132
  • 17.3k

Get the index of the excel sheet line.

May 9 2018 1:38 PM
Friends, good afternoon! I have the following problem, before I used a "FOR" code in the meantime, to improve the performance of the application, I had to change my code to work with lines using DataRow, however, when working with foreach I can not plus grab the index value from my line. I have a excel sheet that I need to get index 6, because line 1 to 5 is header, however I tried to create several ways to create a counter, but take index 1 and not index 6 forward that would be correct. Could someone please help me?
when I used my "FOR" I could read line A6 ahead and the other columns:
  1. for (int i = 5; i <(numberLines - 1); i ++)  
  2. {  
  3. if (process! = null)  
  4. {  
  5. // if the process is not null I search all procinter related to it  
  6. List <ProcessInterest> listprocinter = ProcessInterested.consultProcessor (process.Code);  
  7. if (listprocinter.Exists (o => o.interest == interested))  
  8. //String.Concat (row.ToString ());  
  9. log.Append ("The interested" + process.Interested.Name + ", entered in the line" + (i + 1) + "was added again to the process" + process.NumProcesso + "");  
  10. //log.Append("The interested "+ process.Interested.Name +" was added back to the process "+ process.NumProcesso +" <br> ");  
  11. // log.Append ("The interested" + process.Interested.Name + "was added back to the process" + process.NumProcesso + "<br>");  
  12. setProcInter (process, interested, ds, row);  
  13. }  
  14. else  
  15. {  
  16. // New Process - 6.3  
  17. process = new Process ();  
  18. }  
  19. }  
However, to improve performance I had to implement the foreach in place of the "FOR" and work with the DataRow and line. This is my changed code, but I can not get the index more correctly, can you please help me?
  1. foreach (var line in (IEnumerable <DataRow>) data)  
  2. {  
  3. if (process! = null)  
  4. {  
  5. // if the process is not null I search all procinter related to it  
  6. List <ProcessInterest> listprocinter = ProcessInterested.consultProcessor (process.Code);  
  7. if (listprocinter.Exists (o => o.interest == interested))  
  8. //String.Concat (row.ToString ());  
  9. log.Append ("The interested" + process.Interested.Name + ", entered in the line" + (i + 1) + "was added again to the process" + process.NumberProcess + "");  
  10. //log.Append("The interested "+ process.Interested.Name +" was added back to the process "+ process.NumberProcess +" <br> ");  
  11. // log.Append ("The interested" + process.Interested.Name + "was added back to the process" + process.NumberProcess + "<br>");  
  12. setProcInter (process, interested, ds, row);  
  13. }  
  14. else  
  15. {  
  16. // New Process - 6.3  
  17. process = new Process ();  
  18. process.Interested = interested;  
  19. }  
  20. }