本文整理汇总了Python中openpyxl.writer.excel.ExcelWriter.write_data方法的典型用法代码示例。如果您正苦于以下问题:Python ExcelWriter.write_data方法的具体用法?Python ExcelWriter.write_data怎么用?Python ExcelWriter.write_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openpyxl.writer.excel.ExcelWriter
的用法示例。
在下文中一共展示了ExcelWriter.write_data方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: to_bytes
# 需要导入模块: from openpyxl.writer.excel import ExcelWriter [as 别名]
# 或者: from openpyxl.writer.excel.ExcelWriter import write_data [as 别名]
def to_bytes(self, table, **kargs):
wb = Workbook(optimized_write=True)
ws = wb.create_sheet()
# Determine columns. We may need an extra (first) column which 'names' the row
columns = list(map(str, list(table.get_columns())))
ws.append(columns)
# Write rows to worksheet
for row in table.get_rows():
ws.append(tuple(_get_values(table, row)))
writer = ExcelWriter(wb)
# Need to do a little bit more work here, since the openpyxl library only
# supports writing to a filename, while we need a buffer here..
buffer = io.BytesIO()
with zipfile.ZipFile(buffer, 'w', zipfile.ZIP_DEFLATED) as zf:
writer.write_data(zf)
return buffer.getvalue()