使用 Excel 互操作,您可以这样做。我认为函数名称指向您的 excel 工作簿中定义的函数,否则您必须更改该部分以使用反射(但在这种情况下,您需要方法的接收器,而我没有看到在问题中)。
object hmissing = System.Reflection.Missing.Value;
Xls.Application App = new Xls.ApplicationClass();
App.Visible = true;
Xls.Workbook wb = App.Workbooks.Open(@"c:\tmp\cartel1.xls", hmissing, hmissing, hmissing, hmissing, hmissing, hmissing,
hmissing, hmissing, hmissing, hmissing, hmissing, hmissing, hmissing, hmissing);
Xls.Worksheet ws = (Xls.Worksheet)wb.ActiveSheet;
Xls.Range rng = ws.UsedRange;
Xls.Range hdr = rng.Find("Function Name", hmissing, hmissing, hmissing, hmissing, Microsoft.Office.Interop.Excel.XlSearchDirection.xlNext, hmissing, hmissing, hmissing);
string hdrAdd = hdr.get_Address(hmissing, hmissing, Microsoft.Office.Interop.Excel.XlReferenceStyle.xlA1, hmissing, hmissing);
string[] pcs = hdrAdd.Split('$');
string col = pcs[1];
int row;
int.TryParse(pcs[2], out row);
string methName;
row++;
while ((methName = App.get_Range(col + row.ToString(), hmissing).get_Value(hmissing) as String) != null)
{
App.Run(methName.Split('.')[1], hmissing, hmissing, hmissing, hmissing, hmissing, hmissing, hmissing,
hmissing, hmissing, hmissing, hmissing, hmissing, hmissing, hmissing, hmissing, hmissing, hmissing,
hmissing, hmissing, hmissing, hmissing, hmissing, hmissing, hmissing, hmissing, hmissing, hmissing,
hmissing, hmissing, hmissing);
row++;
}