正如我在SSIS中的C#中编辑脚本任务时显示的标题所示,我遇到了这个问题,我尝试了几种在线找到的解决方案,但是不起作用。你能找出原因吗?

using Microsoft.VisualBasic;using System;
using System.IO;using System.Collections;
using System.Collections.Generic;using System.Data;
using System.Diagnostics;using Excel = Microsoft.Office.Interop.Excel;
using Microsoft.SqlServer.Dts.Runtime;

namespace ST_46fccdfebfc844059ab81e95c062c19e.csproj
{
[System.AddIn.AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{

    #region VSTA generated code
    enum ScriptResults
    {
        Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
        Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
    };
    #endregion

    public void Main()
    {

        string File_name = "c:\\Documents and Settings\\richard.gui\\Desktop\\ARupload.xlsm";
        string Macro_name = "test";

        Excel.Application ExcelObject = default(Excel.Application);

        Excel.Workbooks oBooks = default(Excel.Workbooks);
        Excel.WorkbookClass oBook = default(Excel.WorkbookClass);

        ExcelObject.Visible = true;

        oBooks = ExcelObject.Workbooks;
        oBook = (Excel.WorkbookClass)oBooks.Open(File_name);

        ExcelObject.Run(Macro_name);

        oBook.Save();
        ExcelObject.Application.Quit();
        ExcelObject.DisplayAlerts = true;

        ExcelObject = null;
        Dts.TaskResult = (int)ScriptResults.Success;
    }
}
}

最佳答案

http://msdn.microsoft.com/en-us/library/office/aa168292(v=office.11).aspx

也许尝试这样的事情:

// C#
Excel.Workbook wb = ThisApplication.Workbooks.Open(
"C:\\YourPath\\Yourworkbook.xls",
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing);

关于c# - 方法'Open'/'Run'的重载没有接受'1'参数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16292058/

10-12 22:43