I have a package that creates an Excel sheet (via a T-SQL task) then loads data into it. The customer has specific header requirements which want the spreadsheet designed as such:
ReportName Covers StartDate through EndDate
Name Zip Program SignupDate
The first line is a single column with the second line being 4 separate columns. Now, I can design the spreadsheet to do this, but I end up getting this:
Name Zip Program SignupDate
ReportName Covers StartDate through EndDate
Name Zip Program SignupDate
Two sets of column headers. I've got a fix for it. My devs helped me write a C# program to delete that top "extra" header. The package runs fine from my desktop in BIDS. But when I try to run it on my server, I get the following error:
Error: 2012-10-22 06:23:17.51
Code: 0x00000001
Source: Remove Duplicate Header Row
Description: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Office.Interop.Excel, Version=11.0.0.0,
Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The system cannot find the file specified.
File name: 'Microsoft.Office.Interop.Excel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'
at ST_611a78a7dcaf4b57924f38e8064b3560.csproj.ScriptMain.Main()
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature 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 System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, CultureInfo culture)
at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()
End Error
And the code for the step is:
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using Excel = Microsoft.Office.Interop.Excel;
using System.Reflection;
namespace ST_611a78a7dcaf4b57924f38e8064b3560.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()
{
Excel.Application application = new Microsoft.Office.Interop.Excel.Application();
application.Visible = false;
Excel._Workbook workbook = application.Workbooks.Open(Dts.Variables["NewFileName"].Value.ToString(),
Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
Excel._Worksheet worksheet = (Excel._Worksheet)workbook.Worksheets["Motor"];
worksheet.get_Range("A1", "D1").Font.Bold = true;
worksheet.get_Range("D:D", Missing.Value).ColumnWidth = 25;
worksheet.get_Range("A1", "D1").ColumnWidth = 8.5;
worksheet.get_Range("B1", "B1").set_Value(Missing.Value, "New Header");
worksheet.get_Range("A1", "A1").EntireRow.Delete(Excel.XlDirection.xlUp);
workbook.Save();
application.Quit();
worksheet = null;
workbook = null;
application = null;
Dts.TaskResult = (int)ScriptResults.Success;
}
}
}
I don't know if this has anything to do with the error, but our server setup is a little odd. We have a database server, an application server, and a NAS share. The app server runs the package (after connecting to the db server) and then creates the Excel sheet on our NAS share. Everything works fine with this package until it tries to alter the Excel file out on the NAS share. I've tried everything. Even changing the code from VB to C#. Nothing appears to be working when the package is run from the job on the app server.
Does anyone have any thoughts on what the issue could be?
MCITP:DBA, MCDBA, MCSA