gpt4 book ai didi

python - 如何将 merge_range 和 write_formula 与 xlsxwriter python 结合起来

转载 作者:太空宇宙 更新时间:2023-11-04 03:38:44 25 4
gpt4 key购买 nike

这是我正在尝试的代码。但它不起作用。

import xlsxwriter
....
sheet.merge_range.write_formula('F16:H16', """IF('Original data'!B4<>"",'Original data'!B4,"")""", center)

有没有别的代码可以把两者合二为一呢?我已经在做一些研究,但没有得到任何结果。提前致谢

最佳答案

来自 merge_range() 上的文档:

The merge_range() method writes its data argument using write(). Therefore it will handle numbers, strings and formulas as usual. If this doesn’t handle your data correctly then you can overwrite the first cell with a call to one of the other write_*() methods using the same Format as in the merged cells. See Example: Merging Cells with a Rich String.

这是一个基于您的示例的小示例:

import xlsxwriter

workbook = xlsxwriter.Workbook('example.xlsx')
worksheet1 = workbook.add_worksheet()
worksheet2 = workbook.add_worksheet('Original data')

center = workbook.add_format({'align': 'center', 'fg_color': 'yellow'})


worksheet1.merge_range('F16:H16',
"""=IF('Original data'!B4<>"",'Original data'!B4,"")""",
center)

worksheet2.write('B4', 'Hello')

workbook.close()

输出:

enter image description here

关于python - 如何将 merge_range 和 write_formula 与 xlsxwriter python 结合起来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27632212/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com