Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Visual Studio(SSDT)中的Office PIA错误:未注册类_C#_.net_Excel_Visual Studio 2010_Ssis - Fatal编程技术网

C# Visual Studio(SSDT)中的Office PIA错误:未注册类

C# Visual Studio(SSDT)中的Office PIA错误:未注册类,c#,.net,excel,visual-studio-2010,ssis,C#,.net,Excel,Visual Studio 2010,Ssis,我们有一个正在运行的SQL Server 2012 SSIS包,其中有一个具有以下配置的C#脚本任务。最初是由于无法在名称空间中检测Office而导致的错误,在我添加了两个引用EXCELPIA和ExcelPol之后,该错误就消失了。此外,还有一个错误,如“找不到Policy.11.0.Microsoft.Office.Interop.Excel.config”。因此,我将策略重命名为Policy.12.0.Microsoft.Office.Interop.MSPROJECT.config,如下所

我们有一个正在运行的SQL Server 2012 SSIS包,其中有一个具有以下配置的C#脚本任务。最初是由于无法在名称空间中检测Office而导致的错误,在我添加了两个引用EXCELPIA和ExcelPol之后,该错误就消失了。此外,还有一个错误,如“找不到Policy.11.0.Microsoft.Office.Interop.Excel.config”。因此,我将策略重命名为Policy.12.0.Microsoft.Office.Interop.MSPROJECT.config,如下所示,Visual Studio成功构建了它:D

但现在我在执行过程中遇到了问题,例如,“检索CLSID为{00024500-0000-0000-C000-0000000000 46}的组件的COM类工厂失败,原因是以下错误:80040154类未注册(HRESULT的异常:0x80040154(REGDB_E_CLASSNOTREG))。”

请不要建议安装Office,因为它在没有Office的情况下已成功运行

请帮助我,因为我不是C#/VS专家,我接受了SSDT的工作。请

以下是脚本任务的只读变量: 用户::FileNameExistsPDF,用户::FileNameExportPDF,用户::FolderPathExistsPDF,用户::FolderPathExportPDF

代码:

using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using Microsoft.Office.Interop.Excel;
using System.IO;


namespace ST_7843d274ed184dd59c75bb80b70ab856
{

                public void Main()
                {

            Microsoft.Office.Interop.Excel.Application excelApplication = new Microsoft.Office.Interop.Excel.Application();
            Workbook excelWorkBook = null;



            string paramSourceBookPath = Dts.Variables["User::FolderPathExistsPDF"].Value.ToString() + Dts.Variables["User::FileNameExistsPDF"].Value.ToString();
                        object paramMissing = Type.Missing;



            string paramExportFilePath = Dts.Variables["User::FolderPathExportPDF"].Value.ToString() + Dts.Variables["User::FileNameExportPDF"].Value.ToString();
            XlFixedFormatType paramExportFormat = XlFixedFormatType.xlTypePDF;
            XlFixedFormatQuality paramExportQuality = XlFixedFormatQuality.xlQualityStandard;
            bool paramOpenAfterPublish = false;
            bool paramIncludeDocProps = true;
            bool paramIgnorePrintAreas = true;
            object paramFromPage = Type.Missing;
            object paramToPage = Type.Missing;


            try
            {
                // Open the source workbook.
                excelWorkBook = excelApplication.Workbooks.Open(paramSourceBookPath,
                    paramMissing, paramMissing, paramMissing, paramMissing,
                    paramMissing, paramMissing, paramMissing, paramMissing,
                    paramMissing, paramMissing, paramMissing, paramMissing,
                    paramMissing, paramMissing);

                // Save it in the target format.
                if (excelWorkBook != null)
                    excelWorkBook.ExportAsFixedFormat(paramExportFormat,
                        paramExportFilePath, paramExportQuality,
                        paramIncludeDocProps, paramIgnorePrintAreas, paramFromPage,
                        paramToPage, paramOpenAfterPublish,
                        paramMissing);
            }
            catch (Exception ex)
            {
                // Respond to the error.
            }
            finally
            {
                // Close the workbook object.
                if (excelWorkBook != null)
                {
                    excelWorkBook.Close(false, paramMissing, paramMissing);
                    excelWorkBook = null;
                }

                // Quit Excel and release the ApplicationClass object.
                if (excelApplication != null)
                {
                    excelApplication.Quit();
                    excelApplication = null;
                }

                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }  
                        Dts.TaskResult = (int)ScriptResults.Success;
                }


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

        }
}

嗯,看起来你正在使用Microsoft.Office.Interop.Excel,所以你肯定需要安装Office。我对这个项目还不熟悉,但这里的人告诉我它是在没有Office的情况下运行的!!!我认为你可以通过安装office来避免安装office。你能检查一下这些设备是否安装在这个软件包最后运行的机器上吗?如果“这里的人告诉我它是在没有办公室的情况下运行的”,那么你应该让他们修复它,因为他们显然是专家。马克,是的,Access DB Enginge已经安装了。