0

Good afternoon, I just want to apologize for my English. I am writing a program (using the epplus library), which takes an excel file and looks for matches. When it finds replaces some cells. Everything works fine, but for a long time. I decided to implement Parallel.For, however I get an error NullReferenceException on the condition

ExcelPackage package_map = new ExcelPackage();
ExcelWorksheet worksheet_map;

ExcelPackage package_rep = new ExcelPackage();
ExcelWorksheet worksheet_rep;

package_rep = new ExcelPackage(repFile);
worksheet_rep = package_rep.Workbook.Worksheets[1];
for (int j = 2; j < worksheet_map.Dimension.Rows + 1; j++)
    Parallel.For(2, worksheet_rep.Dimension.Rows + 1, i =>
    {
        if (worksheet_rep.Cells[i, 6].Text == worksheet_map.Cells[j, 1].Text)    
        {
            worksheet_rep.Cells[i, 6].Value = worksheet_map.Cells[j, 4].Text;    
            worksheet_rep.Cells[i, 5].Value = worksheet_map.Cells[j, 3].Text;   
            worksheet_rep.Cells[i, 4].Value = worksheet_map.Cells[j, 2].Text;    
            kol_sov++;
        }
    });
Thomas Fritsch
  • 9,639
  • 33
  • 37
  • 49
Hash
  • 1
  • 1
  • On which line do you have your NullReferenceException ? worksheet_map is never assigned in your snippet and should also raise a NullReferenceException – asidis Oct 10 '18 at 09:35
  • FileInfo mapFile = new FileInfo(Application.StartupPath + "\\Resources\\" + comboBox1.Text+"_ma.xlsx"); //прочитали мепинг package_map = new ExcelPackage(mapFile); worksheet_map = package_map.Workbook.Worksheets[1]; – Hash Oct 10 '18 at 11:42
  • Error on IF operator – Hash Oct 10 '18 at 11:49
  • Try : if (string.Equals(worksheet_rep.Cells[i, 6].Text, worksheet_map.Cells[j, 1].Text) – DanB Oct 10 '18 at 19:41
  • Thanks!! It's WORKING!!! – Hash Oct 15 '18 at 18:10

0 Answers0