簡體   English   中英

如何使用 Python xlwings 設置行高

[英]How to set row height using Python xlwings

我使用 Python xlwings 向現有的 Excel 工作表添加了新工作表。 我想在新工作表中將行高設置為 15。 我怎樣才能做到這一點。?

缺失功能下所述,您始終可以下拉到 pywin32 並查看VBA文檔

在你的情況下,它會像這樣工作:

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

到目前為止你還沒有辦法在 xlwings 中做到這一點,但如果你可以用 openpyxl 做到這一點, 這里是更好地理解的鏈接

# 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') 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM