方法 Open 没有重载需要 15 个参数 (CS1501)
No overload for method Open takes 15 arguments (CS1501)
我正在使用 2013 Excel 并正在测试一个 Web 应用程序,我需要在其中使用代码分析 excel 文件,因此我找到了一个我根据 ranorex 命名修改的代码。但我是 ranorex 的新手,所以几乎没有错误。这是即使在添加引用后仍面临的错误。
方法 'Open' 没有重载需要 15 个参数 (CS1501)
请帮帮我
/
*
* Created by Ranorex
* User: ppatlolla
* Date: 26/08/2015
* Time: 10:57 AM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Drawing;
using System.Threading;
using WinForms = System.Windows.Forms;
using Microsoft.Office.Interop.Excel;
using Ranorex;
using Ranorex.Core;
using Ranorex.Core.Testing;
namespace CCMWebReports
{
/// <summary>
/// Description of ReadExcelFile.
/// </summary>
[TestModule("7FA20A0A-9E9B-4FE2-9DC7-3FAE3AFA5E58", ModuleType.UserCode, 1)]
public class ReadExcelFile : ITestModule
{
/// <summary>
/// Constructs a new instance.
/// </summary>
public ReadExcelFile()
{
// Do not delete - a parameterless constructor is required!
}
/// <summary>
/// Performs the playback of actions in this module.
/// </summary>
/// <remarks>You should not call this method directly, instead pass the module
/// instance to the <see cref="TestModuleRunner.Run(ITestModule)"/> method
/// that will in turn invoke this method.</remarks>
void ITestModule.Run()
{
Mouse.DefaultMoveTime = 300;
Keyboard.DefaultKeyPressTime = 100;
Delay.SpeedFactor = 1.0;
}
}
public partial class Form1 : Form
{
//public Form1()
// {
// InitializeComponent();
// }
private void button1_Click(object sender, EventArgs e)
{
Excel.Application xlApp ;
Excel.Workbook xlWorkBook ;
Excel.Worksheet xlWorkSheet ;
Excel.Range range ;
string str;
int rCnt = 0;
int cCnt = 0;
xlApp = new Excel.ApplicationClass();
xlWorkBook = xlApp.Workbooks.Open("1010-AgentPerformancebyPeriod-2015081214195339.xls", 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
range = xlWorkSheet.UsedRange;
for (rCnt = 1; rCnt <= range.Rows.Count; rCnt++)
{
for (cCnt = 1; cCnt <= range.Columns.Count; cCnt++)
{
str = (string)(range.Cells[rCnt, cCnt] as Excel.Range).Value2 ;
Report.Info(str);
}
}
xlWorkBook.Close(true, null, null);
xlApp.Quit();
releaseObject(xlWorkSheet);
releaseObject(xlWorkBook);
releaseObject(xlApp);
}
private void releaseObject(object obj)
{
try
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
obj = null;
}
catch (Exception ex)
{
obj = null;
Report.Info("Unable to release the Object " + ex.ToString());
}
finally
{
GC.Collect();
}
}
}
}
我认为你的 xlApp.Workbooks.Open
函数中的参数太多。
删除最后一个 'true' 之后的最后 2 个参数,应该可以成功编译:
xlWorkBook = xlApp.Workbooks.Open("1010-AgentPerformancebyPeriod-2015081214195339.xls", 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true);
我正在使用 2013 Excel 并正在测试一个 Web 应用程序,我需要在其中使用代码分析 excel 文件,因此我找到了一个我根据 ranorex 命名修改的代码。但我是 ranorex 的新手,所以几乎没有错误。这是即使在添加引用后仍面临的错误。 方法 'Open' 没有重载需要 15 个参数 (CS1501)
请帮帮我 /
*
* Created by Ranorex
* User: ppatlolla
* Date: 26/08/2015
* Time: 10:57 AM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Drawing;
using System.Threading;
using WinForms = System.Windows.Forms;
using Microsoft.Office.Interop.Excel;
using Ranorex;
using Ranorex.Core;
using Ranorex.Core.Testing;
namespace CCMWebReports
{
/// <summary>
/// Description of ReadExcelFile.
/// </summary>
[TestModule("7FA20A0A-9E9B-4FE2-9DC7-3FAE3AFA5E58", ModuleType.UserCode, 1)]
public class ReadExcelFile : ITestModule
{
/// <summary>
/// Constructs a new instance.
/// </summary>
public ReadExcelFile()
{
// Do not delete - a parameterless constructor is required!
}
/// <summary>
/// Performs the playback of actions in this module.
/// </summary>
/// <remarks>You should not call this method directly, instead pass the module
/// instance to the <see cref="TestModuleRunner.Run(ITestModule)"/> method
/// that will in turn invoke this method.</remarks>
void ITestModule.Run()
{
Mouse.DefaultMoveTime = 300;
Keyboard.DefaultKeyPressTime = 100;
Delay.SpeedFactor = 1.0;
}
}
public partial class Form1 : Form
{
//public Form1()
// {
// InitializeComponent();
// }
private void button1_Click(object sender, EventArgs e)
{
Excel.Application xlApp ;
Excel.Workbook xlWorkBook ;
Excel.Worksheet xlWorkSheet ;
Excel.Range range ;
string str;
int rCnt = 0;
int cCnt = 0;
xlApp = new Excel.ApplicationClass();
xlWorkBook = xlApp.Workbooks.Open("1010-AgentPerformancebyPeriod-2015081214195339.xls", 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
range = xlWorkSheet.UsedRange;
for (rCnt = 1; rCnt <= range.Rows.Count; rCnt++)
{
for (cCnt = 1; cCnt <= range.Columns.Count; cCnt++)
{
str = (string)(range.Cells[rCnt, cCnt] as Excel.Range).Value2 ;
Report.Info(str);
}
}
xlWorkBook.Close(true, null, null);
xlApp.Quit();
releaseObject(xlWorkSheet);
releaseObject(xlWorkBook);
releaseObject(xlApp);
}
private void releaseObject(object obj)
{
try
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
obj = null;
}
catch (Exception ex)
{
obj = null;
Report.Info("Unable to release the Object " + ex.ToString());
}
finally
{
GC.Collect();
}
}
}
}
我认为你的 xlApp.Workbooks.Open
函数中的参数太多。
删除最后一个 'true' 之后的最后 2 个参数,应该可以成功编译:
xlWorkBook = xlApp.Workbooks.Open("1010-AgentPerformancebyPeriod-2015081214195339.xls", 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true);