不能在 epplus 中操作表的单元格“+=”

can not operand "+=" cells of sheets in epplus

尽管如此,我将 epplus 中的所有工作表单元格更改为双工作表,但错误操作数 += 发生在我的 code.this 是我的代码。

sheet.Cells["C1:C"+sheet.Dimension.Rows].Style.Numberformat.Format = "0";
//sheet.Cells["C1:C" + sheet.Dimension.Rows].Value = s;
for (int x = 1; x <= sheet2.Dimension.Rows; x++)
{
   for (int y = 1; y <= sheet.Dimension.Rows; y++)
   {
       if (sheet.Cells[y, 1].Value.ToString() != null)
       {
           if (sheet2.Cells[x, 1].Value.Equals(sheet.Cells[y, 1].Value.ToString()))
           {
               sheet2.Cells[x, 4].Value.GetType<Double>() += sheet.Cells[y, 3].Value.GetType<Double>();
           }
        }
    }
}

错误的原因是因为您正在尝试 += 一个 getter 函数。您只能在可以赋值的对象中执行该操作。

例如,您可以执行以下操作

if (sheet2.Cells[x, 1].Value.Equals(sheet.Cells[y, 1].Value.ToString()))
{
    double cellValue = (double)sheet2.Cells[x, 4].Value;
    cellValue += (double)sheet.Cells[y, 3].Value;
    sheet2.Cells[x, 4].Value = cellvalue;
}

编辑:以下未经测试,但也可以工作:((double)sheet2.Cells[x, 4].Value) += (double)sheet.Cells[y, 3].Value

谢谢你的帮助 你的决心帮助我解决我的代码 tnx。这是代码的分辨率。

for (int x = 1; x <= 604; x++)
            {
                for (int y = 1; y <= sheet.Dimension.Rows; y++)
                {
                    if (sheet.Cells[y, 1].Value.ToString() != null)
                    {
                        if (sheet.Cells[y, 1].Value.Equals(sheet2.Cells[x, 1].Value.ToString()))
                        {

                            double cellValue = Convert.ToDouble(sheet2.Cells[x, 4].Value);
                            cellValue += Convert.ToDouble(sheet.Cells[y, 3].Value);
                            sheet2.Cells[x, 4].Value = cellValue;
                        }
                    }
                }


            }