用于Excel中的word-wrap的Python win32com方法? [英] Python win32com method for word-wrap in Excel?

查看:296
本文介绍了用于Excel中的word-wrap的Python win32com方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要编写一个函数,将会打包活动的Excel工作簿的所有表的内容。除了必要的方法之外,我还写了一切书。我无法在任何地方找到它。有人有任何知识吗?

I need to write a function that will word wrap the contents of all sheets of an active Excel workbook. I have everything written except the necessary method. I am not able to find it anywhere. Does anyone have any knowledge on this?

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用于网页搜索(在谷歌中工作)。在你的情况下,microsoft excel interop word wrap找到 Range.WrapText属性,这表明您应该能够执行类似于

Use "microsoft excel interop yourFunctionOrConstantOrClass" for web searches (works in google). In your case "microsoft excel interop word wrap" finds Range.WrapText property which suggests you should be able to do something like

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

这篇关于用于Excel中的word-wrap的Python win32com方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆