Excel中word wrap的Python win32com方法?
我需要编写一个函数,将word包装活动Excel工作簿所有工作表的内容。除了必要的方法,我什么都写了。我哪儿都找不到。有人知道这件事吗Excel中word wrap的Python win32com方法?,python,excel,win32com,Python,Excel,Win32com,我需要编写一个函数,将word包装活动Excel工作簿所有工作表的内容。除了必要的方法,我什么都写了。我哪儿都找不到。有人知道这件事吗 from win32com.client import Dispatch excel = Dispatch('Excel.Application') def main(): WordWrapColumns() def WordWrapColumns(): excel.ActiveWorkbook.Save() filename = e
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”进行web搜索(在google中可用)。在您的案例中,“MicrosoftExcelInteropWordWrap”会发现这表明您应该能够执行以下操作
for i in range(0,active_sheets):
ws = wb.Worksheets(i+1)
ws.Columns.WrapText = True