簡體   English   中英

自動尺寸評論框

[英]Auto size comment box

我正在使用 win32com 模塊編寫一個 excel 文件。 我正在嘗試的任務之一是向單元格添加注釋並自動調整注釋框大小。 如果未調整大小,則當鼠標懸停在單元格上時,部分評論將不可見。 這是我到目前為止:

from win32com.client import Dispatch
import os

dirpath = os.path.dirname(os.path.realpath(__file__))
outputfile = 'ExcelTest.xlsx'
excel = Dispatch("Excel.Application")

wb = excel.Workbooks.Add()
ws = wb.Worksheets('Sheet1')
ws.Name = 'Test'

ws.Cells(1, 1).Value = 'Hi'
rng = ws.Range(ws.Cells(1, 1), ws.Cells(1, 1))
cmt = rng.AddComment('Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum')
cmt.Shape.TextFrame.Characters().Font.Bold = False
cmt.ShapeRange.ScaleWidth = 3.0
cmt.ShapeRange.ScaleHeight = 3.0

wb.SaveAs(os.path.join(dirpath, outputfile))
excel.Application.Quit()

我認為 ShapeRange.ScaleWidth, ShapeRange.ScaleHeight 是指定注釋框縮放的方法,但我沒有正確獲取屬性並出現錯誤。 理想情況下,我想自動調整評論框的尺寸。 有什么建議?

找到兩種方法:

cmt.Shape.Width = 300
cmt.Shape.Height = 100

或者

cmt.Shape.TextFrame.AutoSize = True

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM