如何删除 .csv 文件中的第一行 [英] How to delete the first row in the .csv file

查看:135
本文介绍了如何删除 .csv 文件中的第一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要删除 CSV 文件的第一行.

I need to delete the first row of the CSV file.

在我的脚本中,我收到了 CSV 文件作为参数,它的第一行包含一些不需要的数据.所以我只需要在处理它之前删除第一行.

In my script I received CSV file as argument and it's first row contains some unwanted data. So I need to remove the first row only before processing it.

推荐答案

我会这样做:

Set fso = CreateObject("Scripting.FileSystemObject")
Set csv = fso.OpenTextFile(WScript.Arguments(...))

If Not csv.AtEndOfStream Then csv.SkipLine  'skip first row

Do Until csv.AtEndOfStream
  line = csv.ReadLine
  'process read line
Loop

csv.Close

当然,您也可以执行 ReadLine 而不处理跳过第一行的返回值,如 Ekkehard.Horner 建议,但 IMO SkipLine 更好地反映了语义.

Of course you could just as well do a ReadLine without processing the returned value for skipping the first line, as Ekkehard.Horner suggested, but IMO SkipLine better reflects the semantics.

这篇关于如何删除 .csv 文件中的第一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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