Python Xlsxwriter 在常量模式下不覆盖

Python Xlsxwriter not overwriting when in constant mode on

我目前在 constant_mode = True 中使用 xlsxwriter。当我尝试覆盖 excel 的某个部分时,它不起作用。但是,当常量模式为 False 时,它​​的工作就像一个魅力。我还阅读了 xlsxwriter 的文档,但我很难理解文档。

当 constant_mode 为真时,有人能告诉我从哪里开始进行 xlsxwriter 操作吗?

谢谢

示例代码:

import xlsxwriter

workbook = xlsxwriter.Workbook('demo.xlsx',{'constant_memory': True})
worksheet = workbook.add_worksheet()


row_max = 10
col_max = 10

some_data = "World"
for row in range(5, row_max):
    for col in range(5, col_max):
        worksheet.write(row, col, some_data)

some_data = "Hello"
for row in range(5, row_max):
    for col in range(5, col_max):
        worksheet.write(row, col, some_data)


workbook.close()  

输出截图:

来自 XslxWriter docs:

constant_memory: Reduces the amount of data stored in memory so that large files can be written efficiently:

workbook = xlsxwriter.Workbook(filename, {'constant_memory': True})

Note, in this mode a row of data is written and then discarded when a cell in a new row is added via one of the worksheet write_() methods. Therefore, once this mode is active, data should be written in sequential row order.

因此,在 constant_memory 模式下无法尝试覆盖前几行中的数据。