如何使用Python设置行高

2024-06-26 17:44:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经使用PythonXLWings将新工作表添加到现有的excel工作表中。我想在新表中将行高设置为15。我该怎么做


Tags: excel中将行高pythonxlwings
2条回答

正如在Missing Features下所解释的,您始终可以下拉到pywin32并检查documentation for VBA

在您的情况下,它的工作原理如下:

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

到目前为止,您还没有办法在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') 

相关问题 更多 >