简体   繁体   English

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

[英]How to remove empty rows using SSIS tools from a flat file source?

I'm trying to remove all empty rows from my flat file in SSIS. 我正在尝试从SSIS中的平面文件中删除所有空行。 I tried using Conditional Split to resolve this problem, but that solution is not the best option for the task I'm working on. 我尝试使用条件拆分解决此问题,但是该解决方案并不是我正在处理的任务的最佳选择。 I was wondering is there any C# code that will delete all empty rows that I can use in Script Component? 我想知道是否有任何C#代码将删除可在脚本组件中使用的所有空行? I'm new with SSIS and c#, so any help would be appreciated. 我是SSIS和c#的新手,因此将不胜感激。

Here's some C# to help you out. 这是一些C#可以帮助您。 You aren't very clear about what a null row means: 您对空行的含义不是很清楚:

This will work a script component and will let you work with the non empty row: 这将使用脚本组件,并使您可以处理非空行:

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]
         }
       }
    }
}

In case your flat file source is Excel, try the approach outlined in the following link. 如果您的平面文件源是Excel,请尝试以下链接中概述的方法。

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

You mentioned that the conditional split is not the best approach, but did not state why. 您提到条件拆分不是最好的方法,但是没有说明原因。 Perhaps the above will help verify that you're applying it correctly, since you are new to SSIS. 由于您是SSIS的新手,因此上述内容可能有助于验证您是否正确应用了它。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM