2

我在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;
    }
}
}
4

1 回答 1

2

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);
于 2013-04-30T04:29:58.780 回答