from xlsxwriter.workbook import Workbook
# Create an new Excel file and add a worksheet.
workbook = Workbook('wrap_text2.xlsx')
worksheet = workbook.add_worksheet()
# Widen the first column to make the text clearer.
worksheet.set_column('A:A', 20)
# Add a cell format with text wrap on.
cell_format = workbook.add_format({'text_wrap': True})
# Write a wrapped string to a cell.
worksheet.write('A1', "Line 1\nLine 2\nLine 3", cell_format)
workbook.close()
免责声明:这在最新版本的Openpyxl中不起作用。看其他答案。
在
openpyxl
中,可以设置wrap_text
对齐属性来包装多行字符串:这在XlsxWriter模块中也是可能的。
下面是一个小的工作示例:
openpyxl>;=2的样式API已更改。下面的代码演示了现代API。
相关问题 更多 >
编程相关推荐