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 に答える