介紹如何使用 Notepad++ 產生彩色排版的程式碼,並將其貼入 Word 文件中。
在 Word 文件中如果需要插入各種程式語言的原始程式碼,可以使用 Notepad++、Visual Studio 或 Eclipse 等具有語法突顯功能的編輯器,將程式碼轉為彩色之後,再貼入 Word 文件中,可以讓文件更美觀,也可讓程式碼更容易閱讀。
以下是以 Notepad++ 編輯器替程式碼上色,貼入 Word 文件的操作步驟。
Step 1
下載並安裝 Notepad++ 編輯器。
Step 2
打開 Notepad++ 編輯器,將原始的程式碼貼上去。
![原始程式碼 原始程式碼](https://officeguide.cc/wp-content/uploads/2020/07/word-insert-code-preserving-format-and-syntax-highlighting-tutorial-examples-20200730-01.png)
在主選單的「語言」中,選擇程式語言。
![選擇程式語言 選擇程式語言](https://officeguide.cc/wp-content/uploads/2020/07/word-insert-code-preserving-format-and-syntax-highlighting-tutorial-examples-20200730-02.png)
Step 4
Notepad++ 除了預設的白底配色,也可以自行選擇喜歡的配色。若要更改配色,可以點選「設定」中的「設定程式語言格式」。
![設定程式語言格式 設定程式語言格式](https://officeguide.cc/wp-content/uploads/2020/07/word-insert-code-preserving-format-and-syntax-highlighting-tutorial-examples-20200730-03.png)
Step 5
在色彩佈景主題設定中,可以自由選擇喜愛的配色主題。
![選擇配色主題 選擇配色主題](https://officeguide.cc/wp-content/uploads/2020/07/word-insert-code-preserving-format-and-syntax-highlighting-tutorial-examples-20200730-04.png)
Step 6
調整好配色的主題之後,在編輯器中選取要複製的程式碼。
![選取程式碼 選取程式碼](https://officeguide.cc/wp-content/uploads/2020/07/word-insert-code-preserving-format-and-syntax-highlighting-tutorial-examples-20200730-05.png)
Step 7
在「外掛」選單中選擇「NppExport」的「Copy all formats to clipboard」,將排版好的程式碼複製起來。
![複製排版的程式碼 複製排版的程式碼](https://officeguide.cc/wp-content/uploads/2020/07/word-insert-code-preserving-format-and-syntax-highlighting-tutorial-examples-20200730-06.png)
Step 8
開啟 Word 文件,貼上剛剛複製的程式碼,這樣就可以看到彩色排版的程式碼了。
![將排版的程式碼貼入 Word 文件 將排版的程式碼貼入 Word 文件](https://officeguide.cc/wp-content/uploads/2020/07/word-insert-code-preserving-format-and-syntax-highlighting-tutorial-examples-20200730-07.png)
Step 9
最後如果感覺程式碼的字型太小,也可以稍微調整一下,這樣插入的程式碼就變得非常漂亮了。
![調整字型大小 調整字型大小](https://officeguide.cc/wp-content/uploads/2020/07/word-insert-code-preserving-format-and-syntax-highlighting-tutorial-examples-20200730-08.png)
參考資料:StackOverflow