如何使用平面文件源中的SSIS工具删除空行?

时间:2018-06-11 16:49:22

标签: c# ssis

我正在尝试从SSIS中的平面文件中删除所有空行。我尝试使用条件分割来解决此问题,但该解决方案不是我正在处理的任务的最佳选择。我想知道是否有任何C#代码将删除我可以在脚本组件中使用的所有空行?我是SSIS和c#的新手,所以任何帮助都会受到赞赏。

2 个答案:

答案 0 :(得分:0)

这里有一些C#来帮助你。你不清楚空行的含义是什么:

这将使脚本组件工作,并允许您使用非空行:

using System.IO; //This gets you to File (Way up top with the rest of the usings)

public static void Main()
{
    string path = @"c:\[where ever you file is located].txt";

    // Check path.
    if (File.Exists(path))
    {
        string[] lines = File.ReadAllLines(path);

       foreach(string line in lines)
       {
         if(!string.IsNullOrEmpty(line)) //Not null or empty
         {
              //[DO STUFF -- use split if you want to go to data flow]
         }
       }
    }
}

答案 1 :(得分:0)

如果您的平面文件源是Excel,请尝试以下链接中概述的方法。

https://devjef.wordpress.com/2014/02/05/ssis-remove-empty-rows-from-excel-import/

您提到条件拆分不是最好的方法,但没有说明原因。也许以上内容有助于验证您是否正确应用它,因为您不熟悉SSIS。

希望这有帮助。

相关问题