ssis 2008, delete contents from excel - ssis

im using SSIS for SQL Server 2008.
My SSIS package grabs data from sql and exports it to an excel file. But everytime it does this I want new data on the excel.
The problem right now is, If i execute the package more than one time I will have the old data plus the new one on the excel file. I only want the new data displayed.
On the SSIS, on the Control Flow tab I have an Data Flow task. On the Data Flow tab I have an OLEDB source and an Excel Destination in order to put the data on the excel.
So im thinking on deleting the contents from the excel on the SSIS every time before the data gets inserted on the excel.
The excel file has an image, a title and the column names. I want these data to stay.
But I want the data from the rows deleted.
How can I do this?
Thanks...

Ok. What I did was to make a copy of the file and load the data on the new file, and everytime the ssis loads it overwrites the file, so I always have new data..........Thanks!!

Related

SSIS destination CSV file getting bad data

I have developed one SSIS package where I need to take records from database and send it in CSV file. While doing so I found that the csv file when opened in excel is showing some column records with = sign eg "=D7". Can you please suggest how to overcome the issue? Thanks,pallabi

In SSIS, add the text file name as a column in the results dataset

Using SSIS, uploading from a text file to SQL Server database table, I need to add the text file name as a column in the results dataset. I am able to create a flat file source, get the data from the file, load into an OLE DB Destination but I am missing the step to add the filename to the dataset.
Basic user using VS, mostly a SQL Production DBA but our developers said to create an SSIS package to upload the daily text file.
In your flat file source, right click on it and go to advanced properties. In the Advanced Properties editor, select the Component Properties tab and then under Custom Properties, there is a FileNameColumnName. Here I used SourceFileName
I attached a data viewer between my flat file source and the next component et voilĂ !

Can we have the mapping for OleDB Source to Excel Destination at runtime rather than at design time?

I am trying to create a SSIS package that will export csv data to an excel file. This package will be called up from C# giving the csv file as input to the package. I am quite new to SSIS and I've been able to produce the expected result with same headers.
I went with the following approach -
Script task - created scripts from the csv headers to create temp table, bulk insert, excel table scripts.
Execute SQL Task - created a temp table in database
Execute SQL Task - Bulk insert csv data into table
Execute SQL Task - Create Excel file
Data Flow Task - OleDB Source to Excel Destination
Execute SQL Task - Drop the temp table created
The challenge I am facing is that my csv may have different headers (both text and number of headers may be different). And I want a single package to serve this purpose.
With the headers being different, the mapping between OleDB Souce to Excel Destination in step 5 above is not working for dynamic headers and is giving unexpected results in the excel output. Is there any way these mappings can be decided at runtime and not at design time.
I don't believe that you can specify the columns or column mappings of a Data Flow at SSIS runtime. You could build the SSIS package on-the-fly, which would allow your C# code to create the column mappings, but the mappings have to be created before the package can run. See Building Packages Programmatically in MSDN for details.
On the other hand, if all you're trying to do is convert a CSV file into an Excel spreadsheet, it would seem logical to me to use the Workbook.SaveAs method of the Office object model.

How can I go throught every tab in Excel file to evaluate header value in SSIS

I've a SSIS solution to import data from Excel file to SQl Server table.
But the Excel file have differents tabs and I need to go for each one evaluating the header value for A1 cell, if it's for sample "Appointment Count", that is the tab I have to imported.
some idea how can I do it?
thanks
Eliana
You can create an OLEDB connection manager, using the Microsoft Jet Provider to open the Excel file. From there, you can create a For Each loop container to iterate through the worksheets therein.
For an example of how to implement this, check here.
*Remember that the MS Jet provider is available in 32-bit only.

How to overwrite Excel destination in SSIS?

I have created a package to fetch data from two SQL Server tables, and using merge join combined this data, then stored the result into an Excel destination.
The first time it works fine. The second time it stores repeated data in the Excel file.
How do I overwrite the Excel file rows?
Yes, Possible!
Here is the solution:
First go to your Excel Destination Click to New Button next to Name of Excel Sheet, copy the DML query inside.
Then put an Execute SQL Task into your Control Flow and connect it to your data flow that contains Excel destination. Set the Connection Type To Excel, Set the Connection to your Excel Destination's Excel Connection Manager, go to SQL Statement and type :
Drop TABLE `put the name of the sheet in the excel query you just copied`
Go
finally paste the query after it.
It is all you need to do to solve the problem.
You can refer to this link for a complete info:
http://dwhanalytics.wordpress.com/2011/04/07/ssis-dynamically-generate-excel-tablesheet/
Yes, Possible!
Using SSIS we can solve this problem:
first of all, crate an Excel format file (Structure Format using Excel Connection Manager) at one location as a template file. Then create a copy of that excel file using FILE SYSTEM TASK in another location and make sure that SET OverwriteDestination=True. Finally, using a data flow task, insert data into the new copied file. whenever we want insert data, it will create a copy of the template excel file and then load the data.
Unfortunately the Excel connection manager does not have a setting that allows overwriting the data. You'll need to set up some file manipulation using the File System Task in the Control Flow.
There are several possibilities, here's one of them. You can create a template file (which just contains the sheet with the header) and prior to the Data Flow Transformation a File System Task copies it over the previously exported file.
The File System Task (MSDN)
For Excel it will append data. There is no such option available for overwriting data.
You have to delete and recreate the file through the File System task.
Using a CSV file with flat-file connection manager would serve your purpose of overwriting.
The best solution for me was using File System Tasks to delete and recreate the Excel files from a template.
What I was trying to do was to send every employee a report with Excel attachment in the same format but different data. In a foreach container for each employee, I get the required data, create an Excel file and send a mail with the Excel file attached.
I first:
Create an Excel template (manually)
Create an original Excel file to be used (manually)
Then in the foreach container:
Delete the original file (SSIS File System Task )
Copy the template as the original file (SSIS File System Task)
Get the data from SQL Server and write them to the original file (SSIS Data Flow Task)
Send the mail (SSIS -> SQL Stored Procedure)