![](/img/trans.png)
[英]How to make excel treat text as string in Clojure using data.csv?
[英]data.csv - appending to new line in CSV (clojure)
我一直在測試這個 csv 包data.csv 。
我設法使寫入 CSV 工作。 我對 clojure/lisp 還是很陌生。
我無法弄清楚(通過測試或通過文檔),如何將數據添加到 csv 中的新行。
API 文檔是這樣說的:
write-csv
function
Usage: (write-csv writer data & options)
Writes data to writer in CSV-format.
Valid options are
:separator (Default \,)
:quote (Default \")
:quote? (A predicate function which determines if a string should be quoted. Defaults to quoting only when necessary.)
:newline (:lf (default) or :cr+lf)
但我無法鍛煉如何使用它。
我正在嘗試為以下代碼添加新行:
(defn writeCSV [name]
(with-open [writer (io/writer filePath)]
(csv/write-csv writer
[[name 2]])))
將name
添加到下一個可用行的位置。
使用io/writer
的:append
選項:
(require
'[clojure.data.csv :as csv]
'[clojure.java.io :as io])
(with-open [writer (io/writer "/tmp/foo.csv" :append true)]
(csv/write-csv writer [["name" 1]]))
(with-open [writer (io/writer "/tmp/foo.csv" :append true)]
(csv/write-csv writer [["name" 2]]))
(println (slurp "/tmp/foo.csv"))
;;=>
name,1
name,2
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.