我们有一个SSIS包,其中有一个脚本任务-并且脚本任务使用的是C#2012版本。工作是打开一个excel文件并修改列宽并保存。在我的本地计算机上一切正常。当我将此程序包部署到生产服务器时。包失败。我收到此错误-
使用CLSID检索组件的COM类工厂 {00024500-0000-0000-C000-000000000046}由于以下原因而失败 错误:80040154未注册类(HRESULT的异常: 0x80040154(REGDB_E_CLASSNOTREG)。
这是脚本任务代码:
public void Main()
{
try
{
// TODO: Add your code here
Excel.Application xlp = new Excel.Application();
Excel.Workbooks wrkbs = xlp.Workbooks;
Excel.Workbook wrkb = wrkbs.Open(Dts.Variables[@"User::Source"].Value.ToString());
Excel.Sheets sht = wrkb.Worksheets;
try
{
//sheet1 formating
Excel.Worksheet wst = (Excel.Worksheet)sht.get_Item(1);
wst.Columns.AutoFit();
wst.Rows.AutoFit();
Excel.Range rngQ = wst.get_Range("Q:Q", Type.Missing);
rngQ.ColumnWidth = 18.43;
Excel.Range rngR = wst.get_Range("R:R", Type.Missing);
rngR.ColumnWidth = 14.86;
Excel.Range rng1 = wst.get_Range("1:1", Type.Missing);
rng1.RowHeight = 15.75;
//sheet2 formating
Excel.Worksheet wst2 = (Excel.Worksheet)sht.get_Item(2);
wst2.Columns.AutoFit();
//sheet3 formating
Excel.Worksheet wst3 = (Excel.Worksheet)sht.get_Item(3);
wst3.Columns.AutoFit();
wrkb.Save();
wrkb.Close();
xlp.Quit();
System.Threading.Thread.Sleep(60000);
}
finally
{
if (sht != null) Marshal.ReleaseComObject(sht);
if (wrkb != null) Marshal.ReleaseComObject(wrkb);
if (wrkbs != null) Marshal.ReleaseComObject(wrkbs);
if (xlp != null) Marshal.ReleaseComObject(xlp);
}
}
catch (Exception em)
{
string er = Dts.Variables[@"User::ERROR"].Value.ToString();
using (StreamWriter sw = File.CreateText(er + "Error_Format_StatusChangeR_" + DateTime.Now.ToString("ddMMyyyyhhmmss") + ".log"))
{
sw.WriteLine(em.Message.ToString());
}
}
Dts.TaskResult = (int)ScriptResults.Success;
}
请帮助我