本文整理汇总了Python中spreadsheetresponsemixin.SpreadsheetResponseMixin.generate_xlsx方法的典型用法代码示例。如果您正苦于以下问题:Python SpreadsheetResponseMixin.generate_xlsx方法的具体用法?Python SpreadsheetResponseMixin.generate_xlsx怎么用?Python SpreadsheetResponseMixin.generate_xlsx使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类spreadsheetresponsemixin.SpreadsheetResponseMixin
的用法示例。
在下文中一共展示了SpreadsheetResponseMixin.generate_xlsx方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GenerateXlsxTests
# 需要导入模块: from spreadsheetresponsemixin import SpreadsheetResponseMixin [as 别名]
# 或者: from spreadsheetresponsemixin.SpreadsheetResponseMixin import generate_xlsx [as 别名]
class GenerateXlsxTests(TestCase):
def setUp(self):
self.data = (('row1col1', 'row1col2'), ('row2col1', 'row2col2'))
self.mixin = SpreadsheetResponseMixin()
def _get_sheet(self, wb):
return wb.get_active_sheet()
def test_returns_workbook_if_no_file_passed(self):
assert type(self.mixin.generate_xlsx(self.data)) == Workbook
def test_if_file_is_passed_it_is_returned_with_content_added(self):
given_content = StringIO()
assert given_content.getvalue() == ''
self.mixin.generate_xlsx(self.data, file=given_content)
assert given_content.getvalue() > ''
def test_adds_row_of_data(self):
wb = self.mixin.generate_xlsx(self.data)
ws = self._get_sheet(wb)
assert ws.cell('A1').value == 'row1col1'
assert ws.cell('B2').value == 'row2col2'
def test_inserts_headers_if_provided(self):
headers = ('ColA', 'ColB')
wb = self.mixin.generate_xlsx(self.data, headers)
ws = self._get_sheet(wb)
assert ws.cell('A1').value == 'ColA'
assert ws.cell('B2').value == 'row1col2'