Quantcast
Channel: SQL Server Integration Services forum
Viewing all articles
Browse latest Browse all 24688

How To Delete Bottom N Rows From Excel File in SSIS Package

$
0
0

Hi,

I need to load data from excel file to SQL database but my excel file bottom 2 rows having company information which i need to delete while loading into SQL database using script task.

I am able to delete bottom 2 rows, if source is flatfile using below script in script task but same script is not working for Excel file.

Declared below 2 variables in ssis package.

User::VarFilePath: Contains source file path

User::VarDeleteBottomNRows: Holds the rows to be deleted from bottom (i.e. 2)

#region Namespacesusing System.IO;using System.Linq;#endregionpublicvoid Main() {// TODO: Add your code herestring FilePath = Dts.Variables["User::VarFilePath"].Value.ToString(); Int32 DeleteBottomNRows = Convert.ToInt32(Dts.Variables["VarDeleteBottomNRows"].Value);string[] lines = System.IO.File.ReadAllLines(FilePath); Array.Reverse(lines); lines= lines.Skip(DeleteBottomNRows).ToArray(); Array.Reverse(lines); System.IO.StreamWriter file =new System.IO.StreamWriter(FilePath); foreach (string line in lines) { // MessageBox.Show(line.ToString()); file.WriteLine(line); } file.Close(); Dts.TaskResult = (int)ScriptResults.Success; }Please suggest how to fix this issue using script task.

Thanks,

Visu


Viewing all articles
Browse latest Browse all 24688

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>