dongyun8138 2012-08-17 09:39
浏览 500

是否可以使用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?

  • 写回答

1条回答 默认 最新

  • doubi8383 2013-03-19 06:10
    关注

    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 !
    
    评论

报告相同问题?

悬赏问题

  • ¥15 一道python难题
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度