我有一个.csv
文件,看起来像这样
Example Company
(999) 999-9999
http://yourwebsite.com
Report Date Range: Dec 26, 2013 - Dec 26, 2013
Exported: Dec 26, 2013
Twitter : Profile Summary
Screen Name,Name,Description,Location,Followers,Following,Listed
SctaSa,statisticalgraph,statistical Screen- The official account for your
organization,Saudi Arabia,6775,8,75
因此,我需要将.csv
文件中的特定数据从SSIS转换中读取,从列"Screen Name"
开始,并添加两列"Report Date Range"& "Exported"
existing in the row number 4&5
将它们放在列列表的末尾之后,将这两列的数据放在数据行和remove the garbage data
的末尾,看起来像那样
Screen Name,Name,Description,Location,Followers,Following,Listed,Exported,Report Date Range
SctaSa,statisticalgraph,statistical Screen- The official account for your organization,Saudi Arabia,6775,8,75,26-Dec-13,26-Dec-13
我使用了这个C#脚本,但没有给我我需要的结果:
public void UpdateCSV(string Pstring)
{
string[] values=File.ReadAllText("C:\\mycsv.csv").Split(new char[]{','});
StringBuilder ObjStringBuilder = new StringBuilder();
for (int i = 0; i < values.Length; i++)
{
if (values[i] == Pstring)
continue;
ObjStringBuilder.Append(values[i]+",");
}
ObjStringBuilder.ToString().Remove(ObjStringBuilder.Length - 1);
File.WriteAllText("C:\\UpdatedCSV.csv",ObjStringBuilder.ToString());
}
我尝试使用这个C#脚本,但它不起作用(i'm not expert in C# so i don't know what's the problem)
我试图使用以下脚本删除任何行开头#
你能给我任何建议吗?!
public override void Input0_ProcessInputRow(Input0Buffer Row)
{
}
base.PreExecute();
List<String> lines = new List<string>();
string line;
System.IO.StreamReader file = new System.IO.StreamReader("c:\\mycsv.csv");
while ((line = file.ReadLine()) != null)
{
lines.Add(line);
}
lines.RemoveAll(l => l.Contains("#"));
using (System.IO.StreamWriter outfile = new System.IO.StreamWriter(outputPath))
{
outfile.Write(String.Join(System.Environment.NewLine, lines.ToArray()));
}
}
答案 0 :(得分:1)
以下是步骤。
ReportDateRange
和Exported
。ReportDateRange
和Exported
设为读写变量。使用以下代码行从CSV文件中提取数据。
var path = @"C:\mycsv.csv"
Dts.variables["ReportDateRange "].value = File.ReadLines(path).ElementAtOrDefault(4);
Dts.variables["Exported"].value = File.ReadLines(path).ElementAtOrDefault(5);
使用数据流从平面文件中提取数据
希望它有所帮助!