
- Python XlsxWriter 教程
- Python XlsxWriter - 首頁
- Python XlsxWriter - 概述
- Python XlsxWriter - 環境設定
- Python XlsxWriter - Hello World
- Python XlsxWriter - 重要類
- Python XlsxWriter - 單元格表示法和範圍
- Python XlsxWriter - 定義名稱
- Python XlsxWriter - 公式和函式
- Python XlsxWriter - 日期和時間
- Python XlsxWriter - 表格
- Python XlsxWriter - 應用篩選器
- Python XlsxWriter - 字型和顏色
- Python XlsxWriter - 數字格式
- Python XlsxWriter - 邊框
- Python XlsxWriter - 超連結
- Python XlsxWriter - 條件格式
- Python XlsxWriter - 新增圖表
- Python XlsxWriter - 圖表格式
- Python XlsxWriter - 圖表圖例
- Python XlsxWriter - 條形圖
- Python XlsxWriter - 折線圖
- Python XlsxWriter - 餅圖
- Python XlsxWriter - Sparklines
- Python XlsxWriter - 資料驗證
- Python XlsxWriter - 綱要和分組
- Python XlsxWriter - 凍結和拆分窗格
- Python XlsxWriter - 隱藏/保護工作表
- Python XlsxWriter - 文字框
- Python XlsxWriter - 插入圖片
- Python XlsxWriter - 頁面設定
- Python XlsxWriter - 頁首和頁尾
- Python XlsxWriter - 單元格註釋
- Python XlsxWriter - 使用 Pandas
- Python XlsxWriter - VBA 宏
- Python XlsxWriter 有用資源
- Python XlsxWriter - 快速指南
- Python XlsxWriter - 有用資源
- Python XlsxWriter - 討論
Python XlsxWriter - 單元格註釋
在 Excel 工作表中,可以出於各種原因插入註釋。其中一個用途是在單元格中解釋公式。此外,Excel 註釋還可以作為其他使用者的提醒或筆記。它們對於與其他 Excel 工作簿交叉引用很有用。
從 Excel 的菜單系統中,註釋功能在功能區的“審閱”選單中可用。

要新增和格式化註釋,XlsxWriter 具有add_comment()方法。此方法的兩個必填引數是單元格位置(以 A1 型別或行和列號表示)和註釋文字。
示例
這是一個簡單的示例 -
import xlsxwriter wb = xlsxwriter.Workbook('hello.xlsx') ws = wb.add_worksheet() data='XlsxWriter Library' ws.set_column('C:C', 25) ws.set_row(2, 50) ws.write('C3', data) text = 'Developed by John McNamara' ws.write_comment('C3', text) wb.close()
輸出
當我們開啟工作簿時,當游標置於其中時,將在 C3 單元格的右上角看到帶有標記的註釋。

預設情況下,註釋在游標懸停在寫入註釋的單元格上之前不可見。您可以透過呼叫工作表物件的show_comment()方法或將各個註釋的可見屬性設定為 True 來顯示工作表中的所有註釋。
ws.write_comment('C3', text, {'visible': True})
示例
在以下程式碼中,放置了三個註釋。但是,C3 單元格中的註釋已將其可見屬性設定為 False。因此,在將游標放置在單元格中之前,無法看到它。
import xlsxwriter wb = xlsxwriter.Workbook('hello.xlsx') ws = wb.add_worksheet() ws.show_comments() data='Python' ws.set_column('C:C', 25) ws.set_row(0, 50) ws.write('C1', data) text = 'Programming language developed by Guido Van Rossum' ws.write_comment('C1', text) data= 'XlsxWriter' ws.set_row(2, 50) ws.write('C3', data) text = 'Developed by John McNamara' ws.write_comment('C3', text, {'visible':False}) data= 'OpenPyXl' ws.set_row(4, 50) ws.write('C5', data) text = 'Developed by Eric Gazoni and Charlie Clark' ws.write_comment('C5', text, {'visible':True}) wb.close()
輸出
它將產生以下輸出 -

您可以設定作者選項以指示單元格註釋的作者是誰。註釋的作者也會顯示在工作表底部的狀態列中。
worksheet.write_comment('C3', 'Atonement', {'author': 'Tutorialspoint'})
可以使用set_comments_author()方法設定所有單元格註釋的預設作者 -
worksheet.set_comments_author('Tutorialspoint')
它將產生以下輸出 -

廣告