所需的CSV工具/解决方案 [英] CSV tool/solution Needed

查看:133
本文介绍了所需的CSV工具/解决方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道任务计划程序可以运行的工具/解决方案吗?它会打开一个大型CSV文件并删除日期列中具有比某些数字还早的单元格值的行?

jim_chance@yahoo.com

Does anyone know of a tool/solution that could be ran by task scheduler that would open a large CSV file and delete rows that have a cell value in a date column older than some numeric value?

jim_chance@yahoo.com

推荐答案

我不知道一个,可以尝试使用google,但是写一个很容易.

实际上,这里有一些代码可以启动它
I don''t know of one, you could try google, but it would be easy enough to write one.

Actually here is a bit of code that could get it started
public void DoFilter(Int32 skipRows, string fileName)
{
    const RegexOptions options = ((RegexOptions.IgnorePatternWhitespace | RegexOptions.Multiline) | RegexOptions.IgnoreCase);
    Regex regex = new Regex(",(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))", options);


    string tmpFileName = Path.GetTempFileName();
    using (var sw = new StreamWriter(tmpFileName))
    {
        using (var filestream = File.OpenText(fileName))
        {
            for (int i = 0; i < skipRows; i++)
            {
                filestream.ReadLine();
                if (filestream.EndOfStream)
                {
                    break;
                }
            }
            while (!filestream.EndOfStream)
            {
                string line = filestream.ReadLine();
                var oo = regex.Split(line);

                //process your data here
                //if(row doen''t match exlusion criteria
                {
                    // write to a new file
                    sw.WriteLine(line);
                }
            }
        }
    }
    //move the new file to the old file when we are finished.
    File.Move(tmpFileName, fileName);
}


这篇关于所需的CSV工具/解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆