Search code examples
c#.netexceladd-in

'Operator '*' cannot be applied to operands of type 'System.__ComObject' and 'double''?


I tried using Convert.ToInt32,it did not work,I receive 'Operator '*' cannot be applied to operands of type 'System.__ComObject' and 'int''.

if (((RibbonCheckBox)sender).Checked)
        {
            try
            {
                double cellValue = sheet.Cells[1, 12].Value2;
                Excel.Range usedRange = sheet.UsedRange;
                foreach (Excel.Range row in usedRange.Rows)
                {

                   for (int i = 0; i < row.Rows.Count; i++)
                   {
                        for (int j = 0; j < row.Columns.Count; j++)
                        {
                            while (sheet.Cells[i + 1, 7] != null)
                            {
                                sheet.Cells[i + 1, 8].Value2 = sheet.Cells[i + 1, 7] * Convert.ToInt32(cellValue);
                            }
                        }
                   }
                }
            }
            catch (Exception ex)
            {

                MessageBox.Show("Exceptie:" + ex);

            }

Solution

  • sheet.Cells[i + 1, 7] is an object, not a value. Use sheet.Cells[i + 1, 7].Value2 instead