How to set row height using Python xlwings

时光毁灭记忆、已成空白 提交于 2020-03-05 00:17:36

问题


I have added new sheet to existing excel sheet using Python xlwings. I want to set row height to 15 in new sheet. How can I do that.?


回答1:


As explained under Missing Features, you can always drop down to pywin32 and check out the documentation for VBA.

In your case, it would work like this:

import xlwings as xw
wb = xw.Book(...)
wb.sheets[0]['1:1'].api.RowHeight = 100



回答2:


there is no way till now you can do it in xlwings but if you're okay to do it with openpyxl here is the link for better understanding

# import openpyxl module
import openpyxl 

# Call a Workbook() function of openpyxl 
# to create a new blank Workbook object 
wb = openpyxl.Workbook() 

# Get workbook active sheet 
# from the active attribute. 
sheet = wb.active 

# writing to the specified cell 
sheet.cell(row = 1, column = 1).value = ' hello '

sheet.cell(row = 2, column = 2).value = ' everyone '

# set the height of the row 
sheet.row_dimensions[1].height = 70

# set the width of the column 
sheet.column_dimensions['B'].width = 20

# save the file 
wb.save('dimension.xlsx') 


来源:https://stackoverflow.com/questions/60520200/how-to-set-row-height-using-python-xlwings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!