You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在WSL2终端Emacs-nox Org-mode中打开Word/Excel文件的方法

解决WSL2终端版Emacs-nox中Org-mode打开Office文件跳转到Windows系统窗口的问题

核心逻辑

WSL2下终端版Emacs默认调用Linux侧程序打开文件,要让Office文件在Windows窗口打开,得修改配置让Emacs调用Windows端的默认关联程序。

具体解决方法

方法1:直接配置Org文件关联(推荐)

在你的Emacs配置文件(~/.emacs或~/.emacs.d/init.el)里加以下代码,针对Office格式指定Windows打开命令:

(setq org-file-apps
      '(("\\.docx\\'" . (lambda (file link)
                          (call-process "cmd.exe" nil 0 nil "/c" "start" "" file)))
        ("\\.xlsx\\'" . (lambda (file link)
                          (call-process "cmd.exe" nil 0 nil "/c" "start" "" file)))
        ("\\.doc\\'" . (lambda (file link)
                         (call-process "cmd.exe" nil 0 nil "/c" "start" "" file)))
        ("\\.xls\\'" . (lambda (file link)
                         (call-process "cmd.exe" nil 0 nil "/c" "start" "" file)))
        (auto-mode . emacs)))

cmd.exe /c start "" <file> 是WSL里调用Windows默认程序的标准命令,会自动用Word/Excel打开对应格式文件。

方法2:用wslview工具简化配置

如果你的WSL2装了wslu工具集(Ubuntu可通过sudo apt install wslu安装),可以用wslview自动转换路径并调用Windows程序,配置更简洁:

(setq org-file-apps
      '(("\\.docx\\|\\.xlsx\\|\\.doc\\|\\.xls\\'" . (lambda (file link)
                                                       (call-process "wslview" nil 0 nil file)))
        (auto-mode . emacs)))

方法3:全局设置所有外部资源用Windows程序打开

要是想让所有外部链接、文件都默认唤起Windows程序,直接设置全局浏览器/打开工具:

(setq browse-url-browser-function
      (lambda (url &rest args)
        (call-process "cmd.exe" nil 0 nil "/c" "start" "" url)))

验证配置

加完配置后,重启Emacs或者用M-x eval-buffer加载配置文件,再用C-c C-o打开Org里的Office链接,就能直接唤起Windows的Word/Excel窗口了。

内容的提问来源于stack exchange,提问作者user1389406

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 10:42:35