簡體   English   中英

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

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

我正在嘗試從SSIS中的平面文件中刪除所有空行。 我嘗試使用條件拆分解決此問題,但是該解決方案並不是我正在處理的任務的最佳選擇。 我想知道是否有任何C#代碼將刪除可在腳本組件中使用的所有空行? 我是SSIS和c#的新手,因此將不勝感激。

這是一些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]
         }
       }
    }
}

如果您的平面文件源是Excel,請嘗試以下鏈接中概述的方法。

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

您提到條件拆分不是最好的方法,但是沒有說明原因。 由於您是SSIS的新手,因此上述內容可能有助於驗證您是否正確應用了它。

希望這可以幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM