gpt4 book ai didi

php - 当optimized_write设置为True时,是否可以使用Openpyxl并行创建多个Excel文件?

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

为了克服 PHPExcel 的内存限制,我们使用 Python 的 openpyxl 库生成 Excel 文件,并使用 thrift 从 PHP 发送要保存在 Excel 文件中的数据。

现在我们已经在对象数组中创建了多个客户端,并尝试在 python 端同时生成多个 excel 文件。当我们将optimized_write设置为False时,我们可以这样做,但当optimized write标志设置为True时,我们不能这样做。

    $ob[$X][$Y] = new PhpPythonExcel();
$ob[$X][$Y]->client->openExcel(True); //openExcel method sets optimized_write flag to True of False.
...
//write something to the files.
...
$ob[$X][$Y]->client->saveFile($fileName);

是否可以这样做,或者有什么可用的技巧吗?

最佳答案

是的,这是可能的,并且不需要破解。对 optimized-writer 稍加修改这可以很容易地测试:

from openpyxl import Workbook

library = []
sheets = []
for x in range(5):
wb = Workbook(optimized_write = True)
library.append(wb)
sheets.append(wb.create_sheet())

for irow in xrange(100):
for idx, ws in enumerate(sheets):
# + idx so they are all different
ws.append(['%d' % (i + idx) for i in xrange(200)])

for idx, wb in enumerate(library):
wb.save('new_big_file_{}.xlsx'.format(idx)) # don't forget to save !

关于php - 当optimized_write设置为True时,是否可以使用Openpyxl并行创建多个Excel文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12003353/

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