CSV Tips for Excel

user-pic
Vote 0 Votes

輸出 UTF-8 格式 CSV, 讓 Excel 能正常讀取, 需加 BOM 檔頭
PHP: echo "\xEF\xBB\xBF"
BASH: echo -n $'\xEF\xBB\xBF'
這種方式只有 Excel 2007 會亂碼, 應該是 Exel 2007 本身的問題, 需用這種方式開啟

有換行的資料用 "" 包起來
例:
ABC,"123
456
789"

第一碼為 0 的一串數字, 讓 0 正常顯示
="0123",="0456"

資料中間有 ", 需用 "" 包起來, 兩個 "" 代表一個 ", 若 " 在文字中間, 可以不用包起來, 一個 " 代表一個 "
例:
"""","ABC""123",ABC"123

可以使用 Excel 函式及儲存格代碼
例:
1.61803398,=INT(A1),"=ROUND(A1,2)"

Leave a comment

About this Entry

This page contains a single entry by Pank published on January 22, 2014 9:33 AM.

XONE for Android was the previous entry in this blog.

MySQL: Can not drop or create specific tblname is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Monthly Archives