Emacs:将 CSV 导入组织模式
Emacs 有一个非常好的扩展,名为 org-mode。
我希望能够轻松地将 CSV 文件加载到组织模式中,而不会造成太大的麻烦。 我所能找到的只是表导入或表捕获,简单地说,它们甚至不能很好地工作。
请注意,我的问题的一部分是其中包含逗号的文本字符串。 1,2,3,4 与 1,2,"3,4" 不同。
是否有一个函数或一个 perl 脚本可以运行将 csv 文件转换为组织模式格式?
谢谢!
Emacs has a very nice extension by the name of org-mode.
I would like to be able to easily load CSV files into org-mode without significant grief. All I've been able to find is table-import or table-capture, which, simply put, don't work even approximately well.
Note that part of my issue is text strings with a comma within them. 1,2,3,4 is different than 1,2,"3,4".
Is there a function out there or a perl script that one could run to transform a csv file into org-mode format?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
来自组织模式手册:
因此,只需将数据粘贴到组织文件中,选择它,然后执行
Cu Cc |
。From the org-mode manual:
So just paste the data into an org file, select it, and do
C-u C-c |
.看一下:
Ch f org-table-convert-region
我总是转换 csv,所以我将其添加到我的 .emacs 中。
更新
这是另一个也考虑引用逗号的函数:
随意改进它:-)。
Have a look at:
C-h f org-table-convert-region
I'm always converting csv so I added this to my .emacs.
update
Here is another function that considers the quoted commas as well :
feel free to improve it :-).
我假设您想将 CSV 专门转换为组织模式表格。 如果情况并非如此,您可能需要更明确地了解问题中的输出格式。
像这样的事情应该可以做到,或者至少给你一个可以破解的起点:
I'm assuming you want to convert your CSV specifically into org-mode tables. If that's not the case, you may want to be more explicit about output format in your question.
Something like this should do it, or at least get you a starting point you can hack on:
尝试这个:
Try this:
这是一个黑客工作,但它有效。
导出 CSV 文件时,请在每个条目周围加引号,然后将所有
","
替换为竖线。最后,我制作了一个执行类似以下操作的宏:(
我不能 100% 确定 | 是否是自插入字符,因此最好记录您自己的宏)
点击表格中间某处的选项卡,并且 org-mode 正确格式化它。 我发现在狭窄的区域内更容易做到这一点。
警告:如果您的输入中有竖线……它可能无法正常工作。 类似的情况应该很容易发现,并且相对容易修复。
一般来说,当将类似文本的内容导入组织模式时,我发现一些智能宏编写和搜索替换的组合是
我希望有帮助的最简单的方法。
Here is a bit of a hack-job, but it works.
when you export the CSV file, force quotes around each entry, then replace all
","
as a vertical bar.Finally, I make a macro that does something like this:
(I am not 100% sure if | is a self-insert-char or not, so its best to record your own macro)
Hit tab somewhere in the middle of the table, and org-mode formats it properly. I find this easier to do in a narrowed region.
Caveat: If you have a vertical bar in your input.. it probably won't work quite right. Situations like that should be easy to spot, and relatively easy to fix.
Generally, when importing something text-like into org-mode, I have found a combination of some smart macro writing, and search-replace to be the easiest way
I hope that helps.