我正在使用2013 Excel并且我正在测试一个Web应用程序,我需要使用代码分析excel文件,所以我找到了一个代码,我已经根据ranorex namings进行了修改。但我是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();
}
}
}
}
答案 0 :(得分:0)
我认为你的// From
PDO::ATTR_PERSISTENT => true
// To
PDO::ATTR_PERSISTENT => false
函数中有太多的参数。
删除最后一个&#39; true&#39;之后的最后两个参数。它应该成功编译:
xlApp.Workbooks.Open