0

I want to overwrite all data in an excel sheet using SSIS. I followed this guide https://dwhanalytics.wordpress.com/2011/04/07/ssis-dynamically-generate-excel-tablesheet/. When I run my package I get the following error:

Description: Executing the query "CREATE TABLE Excel Destination ( clientNr ..." failed with the following error: "Table 'Excel Destination' already exists."

The problem lies with the "Drop Excel Table" Execute SQL Task. The "DROP TABLE Excel Destination" query does not delete the Excel Destination sheet in my case - it just deletes the headers, therefore a new sheet with the exact same name cannot be created. How can I delete the sheet instead of deleting the headers?

0

1 Answer 1

2

You would have to do that through C# / VB.NET script task. SQL task will not let you do what you wanted to do. Here is how you can do that, but basically you will need to get a worksheet by index (hopefully you have that), change the name and then save it. Pretty straight forward in Script task:

object m = System.Reflection.Missing.Value;
Excel.ApplicationClass app = new Excel.ApplicationClass();
Excel.Workbook xls = (Workbook)app.Workbooks.Open(path, m,m,m,m,m,m,m,m,m,m,m,m,m,m);
Excel.Worksheet sheet = (Worksheet)xls.Worksheets.get_Item(1);
sheet.Name = "myName";
xls.Save();
app.Application.Workbooks.Close();
Sign up to request clarification or add additional context in comments.

1 Comment

In the end I decided to create a new excel file each time the SSIS package is initiated and then delete it afterwards. It acomplishes the same result without the need for scripting. Thanks for the contribution - I'm sure your script will help someone in the future.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.