是否可以使用Openpyxl并行创建多个excel文件,而optimize_write设置为True?

To overcome the memory limitations of PHPExcel, we have used Python's openpyxl library to generate the Excel files and sending the data to be saved in Excel files from PHP using thrift.

Now we have created several clients in an array of objects and try to generate multiple excel files at the python side at once. We are able to do so when we are setting the optimized_write to False, but not able to do the same when optimized write flag is set to 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);

Is it possible to do so, or any hack available?

Yes it is possible, and no hack needed. With a slight modification of the optimized-writer routine this can be easily tested:

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 !