<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import , print_function , unicode_literals <EOL> from contextlib import contextmanager <EOL> from xlsxwriter import Workbook <EOL> from . . compat import BytesIO <EOL> class WorkbookWriter ( object ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def xlsx_blob ( cls , categories , series ) : <EOL> """<STR_LIT>""" <EOL> xlsx_file = BytesIO ( ) <EOL> with cls . _open_worksheet ( xlsx_file ) as ( workbook , worksheet ) : <EOL> cls . _populate_worksheet ( workbook , worksheet , categories , series ) <EOL> return xlsx_file . getvalue ( ) <EOL> @ staticmethod <EOL> @ contextmanager <EOL> def _open_worksheet ( xlsx_file ) : <EOL> """<STR_LIT>""" <EOL> workbook = Workbook ( xlsx_file , { '<STR_LIT>' : True } ) <EOL> worksheet = workbook . add_worksheet ( ) <EOL> yield workbook , worksheet <EOL> workbook . close ( ) <EOL> @ classmethod <EOL> def _populate_worksheet ( cls , workbook , worksheet , categories , series ) : <EOL> """<STR_LIT>""" <EOL> worksheet . write_column ( <NUM_LIT:1> , <NUM_LIT:0> , categories ) <EOL> for series in series : <EOL> num_format = ( <EOL> workbook . add_format ( { '<STR_LIT>' : series . number_format } ) <EOL> ) <EOL> series_col = series . index + <NUM_LIT:1> <EOL> worksheet . write ( <NUM_LIT:0> , series_col , series . name ) <EOL> worksheet . write_column ( <NUM_LIT:1> , series_col , series . values , num_format ) </s>
