Python的win32com在Word中换行的方法?

我需要编写一个函数,用来包装活动Excel工作簿所有工作表的内容。 除了必要的方法外,我已经写好了一切。 我无法在任何地方find它。 有没有人有这方面的知识?

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”进行网页search(在google中工作)。 在你的情况下,“microsoft excel interop word wrap”发现Range.WrapText属性 ,这表明你应该能够做一些像

 for i in range(0,active_sheets): ws = wb.Worksheets(i+1) ws.Columns.WrapText = True