我有两张来自不同工作簿的工作表:一张我正在编辑 (xlwkstTempSummary),一张我想从中比较值 (xlwkstSummary)。我想根据导入工作表中的值将背景颜色应用于临时工作表中的单个列。这是我当前代码的片段:
Excel.Workbook xlwkbkImport = books.Open(file_location,misValue, true,
misValue, misValue, misValue, true, misValue, misValue, misValue, false,
misValue, misValue, misValue, 0);
Excel.Sheets sheets = xlwkbkImport.Worksheets;
Excel.Worksheet xlwkstSummary = (Excel.Worksheet)sheets.get_Item(1);
Excel.Range r = xlwkstTempSummary.get_Range("F" + summary_start_row.ToString(), "F" + (summary_start_row + clinic_row_count - 1).ToString());
string file_name = file_location.Name;
string file_directory = Path.GetDirectoryName(file_location);
Excel.FormatConditions r_format = r.FormatConditions;
Excel.FormatCondition c1 = r_format.Add((Excel.XlFormatConditionType)2) /*format based on expression*/,
misValue,
@"=AND(AND($G" + summary_start_row + @"<>""4 Star"", $G" +
summary_start_row + @"<>""5 Star"", $G" +
summary_start_row + @"<>""75th"", $G" +
summary_start_row + @"<>""90th""), $F" +
summary_start_row + @"<VLOOKUP($C" + summary_start_row +
@",'" + file_directory + @"[" + file_name + @"]Summary'!$A$9:$D$41,4,FALSE))",
misValue, misValue, misValue, misValue, misValue);
Excel.Interior c1_interior = c1.Interior;
c1_interior.Color = Color.FromArgb(216, 49, 49); //Red
我目前正在使用 vlookup 从导入的工作表中获取所需的值,并且直接在 excel 中编写表达式时可以正常工作,但是当我运行程序时,出现以下错误:
System.ArgumentException:参数不正确。(来自 HRESULT 的异常:0x80070057 (E_INVALIDARG))在 System.RuntimeType.ForwardCallToInvokeMember(字符串成员名称,BindingFlags 标志,对象目标,Int32 [] aWrapperTypes,MessageData 和 msgData)
我能想到它失败的唯一原因是未能在我的 vlookup 调用中正确解析导入工作簿的名称。更熟悉 Microsoft.Office.Interop.Excel 库的人能否对这个问题有所了解?