使用 XlsxWriter 将单元格中的文本定向为垂直?

Orient text in cell to vertical with XlsxWriter?

我看到了几个关于如何设置文本框(但不是文本框中的单元格)方向的示例。我看到了如何格式化其他东西,比如 bold:

bold_format = workbook.add_format({'bold': True})
worksheet.write('A1', "something", bold_format)

但不是垂直方向的文本。

您可以使用 set_rotation。

import xlsxwriter

workbook = xlsxwriter.Workbook("test.xlsx")
worksheet = workbook.add_worksheet()
worksheet.set_landscape()

bold_format = workbook.add_format({'bold': True})
bold_format.set_rotation(90)

worksheet.write('A1', "something", bold_format)

workbook.close()

有关 set_rotation() 的完整文档,请访问:https://xlsxwriter.readthedocs.io/format.html#format-set-rotation