日期:2014-05-19  浏览次数:20831 次

CSV文件格式问题
下面是csv官方定义规则:  


The   CSV   File   Format  


Each   record   is   one   line       ...but
A   record   separator   may   consist   of   a   line   feed   (ASCII/LF=0x0A),   or   a   carriage   return   and   line   feed   pair   (ASCII/CRLF=0x0D   0x0A).
...but:   fields   may   contain   embedded   line-breaks   (see   below)   so   a   record   may   span   more   than   one   line.  


Fields   are   separated   with   commas.
Example   John,Doe,120   any   st., "Anytown,   WW ",08123  


Leading   and   trailing   space-characters   adjacent   to   comma   field   separators   are   ignored.
So       John     ,       Doe     ,...   resolves   to   "John "   and   "Doe ",   etc.   Space   characters   can   be   spaces,   or   tabs.  


Fields   with   embedded   commas   must   be   delimited   with   double-quote   characters.
In   the   above   example.   "Anytown,   WW "   had   to   be   delimited   in   double   quotes   because   it   had   an   embedded   comma.  


Fields   that   contain   double   quote   characters   must   be   surounded   by   double-quotes,   and   the   embedded   double-quotes   must   each   be   represented   by   a   pair   of   consecutive   double   quotes.
So,   John   "Da   Man "   Doe   would   convert   to   "John   " "Da   Man " " ",Doe,   120   any   st.,...  


A   field   that   contains   embedded   line-breaks   must   be   surounded   by   double-quotes
So:  


    Field   1:   Conference   room   1    
    Field   2:
        John,
        Please   bring   the   M.   Mathers   file   for   review    
        -J.L.
    Field   3:   10/18/2002
    ...  


would   convert   to:  


    Conference   room   1,   "John,    
    Please   bring   the   M.   Mathers   file   for   review    
    -J.L.
    ",10/18/2002,...  


Note   that   this   is   a   single   CSV   record,   even   though   it   takes   up   more   than   one   line   in   the   CSV   file.   This   works   because   the   line   breaks   are   embedded   inside   the   double   quotes   of   the   field.  


Implementation   note:   In   Excel, &nb