產出的資料中,有 "01234" 這樣的資料代碼欄位,由於開頭的 0 是有意義的,但是 Excel 開啟 CSV 時會自動去掉 0,變成 "1234"。

已經試著在產出的 CSV 中將資料包上雙引號,但是沒有用。同事幫我找了一個方法,是把資料開頭加上等號 (=),再包上雙引號,也就是 ="01234"

很神奇的,這樣就不會被去掉 0 囉!

可以參考 "How do I open CSV using Excel without deleting leading zeros?" 這篇 Michael Bramley 的答案:

if you can tinker with the txt file an = sign before the "0012345" eg

="0012345"

seems to fix it for excel to retain the leading zeros

0012345

 

打完收工!

arrow
arrow
    文章標籤
    excel csv
    全站熱搜

    小攻城師 發表在 痞客邦 留言(0) 人氣()