将CSV转换为组织模式
我尝试使用John Kitchin提供的代码 https://stackoverflow.com/a/a/27240183/11376268 转换我的CSV文件到组织模式,但我会收到以下错误消息:
Debugger entered--Lisp error: (void-function loop)
(loop for line in (cdr lines) do (setq values (split-string line ",")) (loop for property in properties for value in values do (org-entry-put (point) property value)))
(let ((lines (let ((temp-buffer (generate-new-buffer " *temp*" t))) (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (insert-file-contents "data.csv") (split-string (buffer-string) "\n")) (and (buffer-name temp-buffer) (kill-buffer temp-buffer)))))) (properties) (values)) (setq properties (split-string (car lines) ",")) (loop for line in (cdr lines) do (setq values (split-string line ",")) (loop for property in properties for value in values do (org-entry-put (point) property value))))
(progn (let ((lines (let ((temp-buffer (generate-new-buffer " *temp*" t))) (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (insert-file-contents "data.csv") (split-string (buffer-string) "\n")) (and (buffer-name temp-buffer) ...))))) (properties) (values)) (setq properties (split-string (car lines) ",")) (loop for line in (cdr lines) do (setq values (split-string line ",")) (loop for property in properties for value in values do (org-entry-put (point) property value)))))
elisp--eval-last-sexp(nil)
eval-last-sexp(nil)
funcall-interactively(eval-last-sexp nil)
command-execute(eval-last-sexp)
我使用GNU EMACS 28.1(构建2,X86_64-W64-MINGW32)。
我做错了什么?
data.csv看起来像这样:
Name,Tel,Mobile,Fax
John,11111,22222,33333
我使用的代码:
(let ((lines (with-temp-buffer
(insert-file-contents "data.csv")
(split-string (buffer-string) "\n")))
(properties)
(values))
(setq properties (split-string (car lines) ","))
(loop for line in (cdr lines)
do
(setq values (split-string line ","))
(loop for property in properties
for value in values
do
(org-entry-put (point) property value))))
I tried to use the code provided by John Kitchin in https://stackoverflow.com/a/27240183/11376268 to convert my CSV file to org mode but I get the following error message:
Debugger entered--Lisp error: (void-function loop)
(loop for line in (cdr lines) do (setq values (split-string line ",")) (loop for property in properties for value in values do (org-entry-put (point) property value)))
(let ((lines (let ((temp-buffer (generate-new-buffer " *temp*" t))) (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (insert-file-contents "data.csv") (split-string (buffer-string) "\n")) (and (buffer-name temp-buffer) (kill-buffer temp-buffer)))))) (properties) (values)) (setq properties (split-string (car lines) ",")) (loop for line in (cdr lines) do (setq values (split-string line ",")) (loop for property in properties for value in values do (org-entry-put (point) property value))))
(progn (let ((lines (let ((temp-buffer (generate-new-buffer " *temp*" t))) (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (insert-file-contents "data.csv") (split-string (buffer-string) "\n")) (and (buffer-name temp-buffer) ...))))) (properties) (values)) (setq properties (split-string (car lines) ",")) (loop for line in (cdr lines) do (setq values (split-string line ",")) (loop for property in properties for value in values do (org-entry-put (point) property value)))))
elisp--eval-last-sexp(nil)
eval-last-sexp(nil)
funcall-interactively(eval-last-sexp nil)
command-execute(eval-last-sexp)
I use GNU Emacs 28.1 (build 2, x86_64-w64-mingw32).
What have I done wrong?
data.csv looks like this:
Name,Tel,Mobile,Fax
John,11111,22222,33333
The code I used:
(let ((lines (with-temp-buffer
(insert-file-contents "data.csv")
(split-string (buffer-string) "\n")))
(properties)
(values))
(setq properties (split-string (car lines) ","))
(loop for line in (cdr lines)
do
(setq values (split-string line ","))
(loop for property in properties
for value in values
do
(org-entry-put (point) property value))))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
按原样插入普通的CSV文件,在缓冲区中标记该区域,并致电MX org-table-convert-region ret。
Insert a plain csv-file as is, mark the region in buffer and call M-x org-table-convert-region RET.