我试图制定总结案文。 但是,如果使用包装字句,则自动升高。 我怎么能打上汽车。
Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...
我试图制定总结案文。 但是,如果使用包装字句,则自动升高。 我怎么能打上汽车。
您需要查阅<代码>RowDimension中相关行的物体,特别是高度特性:
rd = ws.row_dimensions[3] # get dimension for row 3
rd.height = 25 # value in points, there is no "auto"
2. 您可使用行文_或一栏,确定高或宽度:
# set the height of the row
sheet.row_dimensions[1].height = 20
# set the width of the column
sheet.column_dimensions[ B ].width = 20
与此类似,我的工作是:
from math import ceil
factor_of_font_size_to_width = {
# TODO: other sizes
12: {
"factor": 0.8, # width / count of symbols at row
"height": 16
}
}
def get_height_for_row(sheet, row_number, font_size=12):
font_params = factor_of_font_size_to_width[font_size]
row = list(sheet.rows)[row_number]
height = font_params["height"]
for cell in row:
words_count_at_one_row = sheet.column_dimensions[cell.column_letter].width / font_params["factor"]
lines = ceil(len(str(cell.value)) / words_count_at_one_row)
height = max(height, lines * font_params["height"])
return height
for i in range(0, sheet.max_row):
# [i + 1] - because the lines are numbered starting at 1
sheet.row_dimensions[i + 1].height = get_height_for_row(sheet, i)
If your data stored in DataFrame, I would recommend you to use StyleFrame. It automatically auto-adjust columns width and rows height and also have some nice features.
https://github.com/Deep Space2/StyleFrame”rel=“nofollow”>eframe
Try:
col_width = []
for i in range(len(next(ws.iter_rows()))):
col_letter = get_column_letter(i + 1)
minimum_width = 20
current_width = ws.column_dimensions[col_letter].width
if not current_width or current_width < minimum_width:
ws.column_dimensions[col_letter].width = minimum_width
col_width.append(ws.column_dimensions[col_letter].width)
for i, row in enumerate(ws):
default_height = 12.5 # Corresponding to font size 12
multiples_of_font_size = [default_height]
for j, cell in enumerate(row):
wrap_text = True
vertical = "top"
if cell.value is not None:
mul = 0
for v in str(cell.value).split(
):
mul += math.ceil(len(v) / col_width[j]) * cell.font.size
if mul > 0:
multiples_of_font_size.append(mul)
cell.alignment = Alignment(wrap_text=wrap_text, vertical=vertical)
original_height = ws.row_dimensions[i + 1].height
if original_height is None:
original_height = default_height
new_height = max(multiples_of_font_size)
if original_height < new_height:
ws.row_dimensions[i + 1].height = new_height
最新版本。
它并不完美。 如果你希望更好,你可能必须使用单一航天体或<条码><>>。
你们只能把一只高到零。 如果你这样做,那么,在xlsx1/worksheets/sheet.xml档案中,浏览器具没有固定的大小。 然后,Excel将根据内容自动调整行顶。
#Autofit the row height
sheet.row_dimensions[1].height = None
Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...
I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...
Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...
Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...
I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...
Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...
Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...
I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...