'Operator '*' 不能应用于类型 'System.__ComObject' 和 'double'' 的操作数?
'Operator '*' cannot be applied to operands of type 'System.__ComObject' and 'double''?
我尝试使用 Convert.ToInt32,它没有用,我收到 '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);
}
sheet.Cells[i + 1, 7]
是一个对象,不是一个值。使用 sheet.Cells[i + 1, 7].Value2
代替
我尝试使用 Convert.ToInt32,它没有用,我收到 '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);
}
sheet.Cells[i + 1, 7]
是一个对象,不是一个值。使用 sheet.Cells[i + 1, 7].Value2
代替