将CSV转换为组织模式

发布于 2025-02-08 07:17:48 字数 2224 浏览 3 评论 0原文

我尝试使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

木格 2025-02-15 07:17:48

按原样插入普通的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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文