JMP 是一款功能極為強大的資料分析與處理工具。具體來說,Tabulate 平台以及其他許多支援生成嵌入式表格的平台,使用戶能夠快速輕鬆地產生摘要和洞察。使用者通常希望將這些表格嵌入到 Microsoft Word、Apache 的 OpenOffice 或 LibreOffice 中。所有這些創作工具都支援讀取和寫入 Office Open XML 標準,尤其是 DOCX 檔案。
我為本文創建的插件旨在幫助您將 JMP 會話中的表格輸出轉換為 DOCX 文件,並充分利用所有格式化和樣式化功能。該插件使用 python-docx 套件 ( https://pypi.org/project/python-docx/ ) 和 JMP/Python 整合來完成此任務。此外,還可以指定先前建立的包含現有樣式化表格的 DOCX 文件,以便使用者建立用於 JMP 表格的格式範本。最後,如果 DOCX 範本包含「標籤」(文件中以 ${JMP_ 開頭並以 } 結尾的文本,例如 ${JMP_TABLE1}),則該插件將在標籤所在的位置嵌入表格。
該插件使用獨立函數編寫,可以從 UI 外部調用,使用戶能夠將 DOCX 表的建立合併到新的或現有的工作流程中。
製表至 DOCX 表格 UI
將插件安裝到您的 JMP 會話將會將 python-docx 套件安裝到您的 JMP Python 環境中,並在插件選單中建立選單項目:
按一下該選單項目將啟動 UI 並收集 JMP 會話中所有表格和製表的清單。
如果您在啟動 UI 後開啟任何新表或建立新的製表,可以點擊刷新按鈕來更新清單。選擇清單中的某個表格/製表將顯示所選內容的縮圖。如果未選擇任何模板 DOCX 文件,則生成的 DOCX 表將不套用任何樣式:
點選「瀏覽」按鈕,您可以選擇一個 DOCX 檔案作為範本。該插件提供了 4 個範例 DOCX 檔案模板,並將它們複製到您的 DOCUMENTS 資料夾中。點擊「檢視」按鈕,可以使用您預設的 DOCX 檔案檢視/編輯應用程式開啟所選的 DOCX 檔案範本。 TabulateToDocxTableTemplate1.docx 檔案包含以下樣式化的表格:
使用該模板,生成的輸出現在如下所示:
TabulateToDocxTableTemplate2 和 3 只是不同的表格樣式。
第四個模板示範了標記功能。選擇該範本後,UI 中會啟用一個新選項,讓您選擇要將表格插入到哪個標記中。
現在,不再建立僅包含樣式化表格的空白文檔,而是使用標籤後段落中的表格樣式將其插入到標籤位置的文檔中:
如上所述,即使插件停止運行,此功能仍會作為獨立函數存在,可以從其他 JSL 進程呼叫。相關參數說明如下:
// TabulateToDocxTable:createDocxTable is a function that uses Python to generate a three-line DOCX version of a JMP Tabulate.
//
// tb - required - a reference to a JMP Table, TabulateBox (DisplayBox), or a Tabulate platform
// templatePath - optional - a string for the path of a DOCX file from which to glean the table styling (default Empty() - use the default styling)
// tag - optional - a string for the ${...} enclosed text in the DOCX template that the rendered table will replace. Specifying this option will first copy the DOCX
// into the outputFilePath and modify that copy of the DOCX
// outputFilePath - optional - a string for the path where to write the DOCX file (default "$DOCUMENTS/JMPDocxTable.docx" - JMPDocxTable.docx in the user's Documents folder)
//
TabulateToDocxTable:createDocxTable = function({tb, templatePath=Empty(), tag=Empty(), outputFilePath=Empty()})
該插件可在 JMP 18 和 19 版本以及 Windows 和 Mac 平台上運行。
:megaphone:我們期待您的回饋!
我們正在嘗試一些與眾不同的功能,很想聽聽您對這項功能的想法。在您試用完外掛後,請花點時間填寫以下問卷。