【问题标题】:Unable to use SSIS to open Excel file无法使用 SSIS 打开 Excel 文件
【发布时间】:2010-11-25 15:34:03
【问题描述】:

我正在尝试使用 SSIS 打开 Excel 文件并在将数据导入 SQL Server 之前刷新数据。我的 dtsx 包在尝试打开 Excel 文件的代码行上失败。

代码很简单,取自here

这是我正在使用的代码:

public void Main()
{
    // TODO: Add your code here
    Dts.TaskResult = (int)ScriptResults.Success;

    Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
    Microsoft.Office.Interop.Excel.Workbook wb;

    wb = excel.Workbooks.Open(@"C:\Test.xlsx",0, false, null, null, null, true, null, null, null, null, null, null, null, null);
    //wb.RefreshAll();
    //wb.Save();
    //wb.Close(null, null, null);
    excel.Quit();

    System.Runtime.InteropServices.Marshal.ReleaseComObject(excel);


}

报错信息如下:

Error: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.InteropServices.COMException (0x800A03EC): Exception from HRESULT: 0x800A03EC
   at Microsoft.Office.Interop.Excel.Workbooks.Open(String Filename, Object UpdateLinks, Object ReadOnly, Object Format, Object Password, Object WriteResPassword, Object IgnoreReadOnlyRecommended, Object Origin, Object Delimiter, Object Editable, Object Notify, Object Converter, Object AddToMru, Object Local, Object CorruptLoad)
   at ST_2177878595ee4288864728b04a894c16.csproj.ScriptMain.Main()
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
   at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()

我目前正在使用以下配置的测试机器:

  • Visual Studio 2008 投标
  • Office 2010
  • Office 2010 PIA

有没有人对如何使它工作有任何建议?

【问题讨论】:

  • 什么是操作系统?具体来说,它是 32 位还是 64 位操作系统?如果您在 64 位计算机上并尝试访问 Excel,则需要告知 SSIS 在 32 位模式下工作。
  • 它是 64 位,但“Run64bitRuntime”属性设置为 false。

标签: c# excel ssis


【解决方案1】:

使用Type.Missing 代替null。在每个变量之前还有ref。见http://msdn.microsoft.com/en-us/library/system.type.missing(v=VS.90).aspx

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-10
    • 2018-04-01
    • 2020-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-25
    相关资源
    最近更新 更多