如何使用 Python xlwings 设置行高
How to set row height using Python xlwings
我使用 Python xlwings 添加了新的 sheet 到现有的 excel sheet。我想在新 sheet 中将行高设置为 15。我该怎么做。?
直到现在你还没有办法在 xlwings 中做到这一点,但如果你可以用 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')
如 Missing Features, you can always drop down to pywin32 and check out the documentation for VBA 所述。
在你的情况下,它会像这样工作:
import xlwings as xw
wb = xw.Book(...)
wb.sheets[0]['1:1'].api.RowHeight = 100
我使用 Python xlwings 添加了新的 sheet 到现有的 excel sheet。我想在新 sheet 中将行高设置为 15。我该怎么做。?
直到现在你还没有办法在 xlwings 中做到这一点,但如果你可以用 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')
如 Missing Features, you can always drop down to pywin32 and check out the documentation for VBA 所述。
在你的情况下,它会像这样工作:
import xlwings as xw
wb = xw.Book(...)
wb.sheets[0]['1:1'].api.RowHeight = 100