[英]Python win32com method for word-wrap in Excel?
我需要編寫一個函數,該函數將自動包裝活動Excel工作簿的所有工作表的內容。 除了必要的方法,我已經寫了所有東西。 我在任何地方都找不到。 有人對此有任何知識嗎?
from win32com.client import Dispatch
excel = Dispatch('Excel.Application')
def main():
WordWrapColumns()
def WordWrapColumns():
excel.ActiveWorkbook.Save()
filename = excel.ActiveWorkbook.FullName
wb = excel.Workbooks.Open(filename)
#Activate all sheets
active_sheets = wb.Sheets.Count
for i in range(0,active_sheets):
excel.Worksheets(i+1).Activate()
# Word wrap all columns in sheet
# What command goes here????
#Save and close workbook
wb.Save()
wb.Close()
excel.Quit()
if __name__ == '__main__':
main()
使用“ microsoft excel interop yourFunctionOrConstantOrClass”進行網絡搜索(適用於Google)。 在您的情況下,“ Microsoft Excel互操作性自動換行”會找到Range.WrapText屬性 ,這建議您應該能夠執行以下操作
for i in range(0,active_sheets):
ws = wb.Worksheets(i+1)
ws.Columns.WrapText = True
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.