Marvin's Blog【程式人生】

Ability will never catch up with the demand for it

22 Oct 2019

在Word中画PlantUML图

PlantUML带有一个Word Add-in,可以到PlantUML Word Template下载。

下载到的文件是PlantUML_Template_v34.dotm。

官方的安装说明:

  • install the right template version in Word
    • copy the (.dotm) file in to %appdata%\Microsoft\Word\STARTUP
    • note: .dotm = Word Doc Template (office 2007 and newer) with Macro’s enabled
  • copy Plantuml.jar to %appdata%\Microsoft\Word\STARTUP folder
  • install GraphViz
    • https://graphviz.gitlab.io/_pages/Download/Download_windows.html
      • use installer if you have rights to install applications; this will install graphviz in your program files (x86)
      • use zip for portable installation
        • extract in %appdata%\GraphViz
        • (executable is then in %appdata%\GraphViz\release\bin\dot.exe)
    • if alternative portable installation, please set environment variable GRAPHVIZ_DOT to location of DOT.EXE
  • restart Word. You now should have a PlantUML menu!

但是上面的操作在Office 365的Word中并不工作。验证可以工作的方式是:

  • 将PlantUML_Template_v34.dotm 放到C:\Program Files (x86)\Microsoft Office\Office16\STARTUP目录
  • 将plantuml.jar放到%APPDATA%\Microsoft\Templates(展开以后是C:\Users\janedoe\AppData\Roaming\Microsoft\Templates)

这样PlantUML的工具栏可以出现在Word中,可以画Sequence图(画状态图估计要安装GraphViz)。

修改模板

PlantUML Word Template默认的生成的图片不是居中对齐的,如果需要居中对齐显示,需要修改模板源码,在往Word插入图片的时候调整对齐:

currentparagraph.ParagraphFormat.Alignment = wdAlignParagraphCenter

因为PlantUML_Template_v34.dotm是带宏的,默认是被禁止的(因为有macro protection)。需要放在C:\Program Files (x86)\Microsoft Office\Office16\STARTUP中打开编辑才可以。

参考

(完)