在一个Excel单元格中的string,读取并作为parameter passing给方法

using Microsoft.VisualStudio.TestTools.UnitTesting; using System; using Excel = Microsoft.Office.Interop.Excel; namespace Something { [TestClass] public class CBMain:Base { [TestMethod] public void Main() { try { string ExcelFilePath = "D:\\Excel.xlsx"; Excel.Application exlApp; Excel.Workbook exlWorkBook; Excel.Worksheet exlWorkSheet; Excel.Range exlRange; exlApp = new Excel.Application(); exlWorkBook = exlApp.Workbooks.Open(@ExcelFilePath); exlWorkSheet = (Excel.Worksheet)exlWorkBook.Worksheets.get_Item(1); exlRange = exlWorkSheet.UsedRange; int exlRowCount = exlRange.Rows.Count; int exlColumnCount = exlRange.Columns.Count; int rcount = 1, ccount = 1; for (rcount = 3; rcount <= exlRowCount; rcount++) { string[] ExcelToMethod1 = (exlRange.Cells[rcount, (ccount + 8)] as Excel.Range).Value2; string[] ExcelToMethod1 = (exlRange.Cells[rcount, (ccount + 10)] as Excel.Range).Value2; Console.WriteLine(ExcelToMethod1 + " | " + ExcelToMethod1 ); //**Calling method for creating program ClassName Program = new ClassName(); Program.MethodCall(ExcelToMethod1 ,ExcelToMethod2); } } catch(Exception e) { Console.WriteLine(e); } //Console.WriteLine(exlRowCount); //Console.WriteLine(exlColumnCount); } } } 

我想从Excel工作表中读取值并将其作为parameter passing给方法。 在Excel中,值在一个单元格中存储为{"Var1","Var2","Var3"} 。 所以当我试图把它们作为一个整体variables传递时,我得到了下面的错误

Microsoft.CSharp.RuntimeBinder.RuntimeBinderException:无法在System.Dynamic.UpdateDelegates.UpdateAndExecute1 [T0,TRet](CallSite站点,T0)CallSite.Target(Closure,CallSite,Object)上隐式地将types“string”转换为“string []” arg0)在D:\ GitAutomation \ BrandmuscleAutomation \ Tests \ ChannelBuilder \ MarketingFundProgram \ Method.cs中的BrandmuscleAutomation.Tests.ChannelBuilder.MarketingFundProgram.CBMain.CBMainCall()中:第42行

Excel_Stored
在这里输入图像说明