コード例 #1
1
ファイル: excel.py プロジェクト: ericgazoni/openpyxl
def save_virtual_workbook(workbook):
    """Return an in-memory workbook, suitable for a Django response."""
    writer = ExcelWriter(workbook)
    temp_buffer = BytesIO()
    try:
        archive = ZipFile(temp_buffer, 'w', ZIP_DEFLATED)
        writer.write_data(archive)
    finally:
        archive.close()
    virtual_workbook = temp_buffer.getvalue()
    temp_buffer.close()
    return virtual_workbook
コード例 #2
0
ファイル: helper.py プロジェクト: adammorris/openpyxl
def get_xml(xml_node):

    io = BytesIO()
    if version_info[0] >= 3 and version_info[1] >= 2:
        ElementTree(xml_node).write(io, encoding='UTF-8', xml_declaration=False)
        ret = str(io.getvalue(), 'utf-8')
        ret = ret.replace('utf-8', 'UTF-8', 1)
    else:
        ElementTree(xml_node).write(io, encoding='UTF-8')
        ret = io.getvalue()
    io.close()
    return ret.replace('\n', '')
コード例 #3
0
def get_xml(xml_node):

    io = BytesIO()
    if version_info[0] >= 3 and version_info[1] >= 2:
        ElementTree(xml_node).write(io, encoding='UTF-8', xml_declaration=False)
        ret = str(io.getvalue(), 'utf-8')
        ret = ret.replace('utf-8', 'UTF-8', 1)
    else:
        ElementTree(xml_node).write(io, encoding='UTF-8')
        ret = io.getvalue()
    io.close()
    return ret.replace('\n', '')
コード例 #4
0
ファイル: excel.py プロジェクト: ericgazoni/openpyxl
 def _write_images(self, images, archive, image_id):
     for img in images:
         buf = BytesIO()
         img.image.save(buf, format= 'PNG')
         archive.writestr(PACKAGE_IMAGES + '/image%d.png' % image_id, buf.getvalue())
         image_id += 1
     return image_id
コード例 #5
0
 def _write_images(self, images, archive, image_id):
     for img in images:
         buf = BytesIO()
         img.image.save(buf, format='PNG')
         archive.writestr(PACKAGE_IMAGES + '/image%d.png' % image_id,
                          buf.getvalue())
         image_id += 1
     return image_id
コード例 #6
0
def save_virtual_workbook(workbook):
    """Return an in-memory workbook, suitable for a Django response."""
    writer = ExcelWriter(workbook)
    temp_buffer = BytesIO()
    try:
        archive = ZipFile(temp_buffer, 'w', ZIP_DEFLATED)
        writer.write_data(archive)
    finally:
        archive.close()
    virtual_workbook = temp_buffer.getvalue()
    temp_buffer.close()
    return virtual_workbook