我有一个sis软件包,可以将模板复制到文件夹并使用文件系统任务相应地命名。然后在我的数据流任务中,我从查询中提取数据并写入刚刚创建的excel文件。在“启动用户” Excel应用程序DCOM设置下,此方法可以正常工作。然后,我有一个脚本任务重新格式化了原始excel文件中的数据类型。但是,除非我将DCOM配置设置为使用“交互式用户”,否则该作业将无法执行我的脚本任务。问题是,即使我的用户帐户已登录,也无法使用,除非我主动rdp进入服务器并在计算机上打开窗口。我可以在我的代码中或其他地方包含某种解决方法,以避免必须使用交互式用户设置吗?这是我的脚本:public void Main()
{
string datetime = DateTime.Now.ToString("yyyyMMddHHmm");
try
{
string FileName = Dts.Variables["User::FullDestinationFile"].Value.ToString();
//Init
Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
xlApp.Visible = false;
//Set active worksheet
Workbook xlWorkbook = xlApp.Workbooks.Open(FileName);
Sheets xlSheets = xlWorkbook.Worksheets;
Worksheet sheet = (Worksheet)xlApp.Worksheets[1];
sheet.Select(Type.Missing);
//Set formatting on columns
Range pDate = sheet.Range[sheet.Cells[5, 1], sheet.Cells[sheet.UsedRange.Rows.Count, 1]];
pDate.NumberFormat = "General";
pDate.HorizontalAlignment = XlHAlign.xlHAlignCenter;
//Save and Close
xlWorkbook.Save();
xlWorkbook.Close(true);
Dts.TaskResult = (int)ScriptResults.Success;
}
catch (Exception exception)
{
// Create Log File for Errors
using (StreamWriter sw = File.CreateText(Dts.Variables["User::FullDestinationFile"].Value.ToString() + datetime + ".log"))
{
sw.WriteLine(exception.ToString());
Dts.TaskResult = (int)ScriptResults.Failure;
}
}
}
0 个答案:
没有答案