Python xlwt.easyxf() Examples
The following are 30
code examples of xlwt.easyxf().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
xlwt
, or try the search function
.
![](https://www.programcreek.com/common/static/images/search.png)
Example #1
Source File: excel.py From recruit with Apache License 2.0 | 11 votes |
def __init__(self, path, engine=None, encoding=None, mode='w', **engine_kwargs): # Use the xlwt module as the Excel writer. import xlwt engine_kwargs['engine'] = engine if mode == 'a': raise ValueError('Append mode is not supported with xlwt!') super(_XlwtWriter, self).__init__(path, mode=mode, **engine_kwargs) if encoding is None: encoding = 'ascii' self.book = xlwt.Workbook(encoding=encoding) self.fm_datetime = xlwt.easyxf(num_format_str=self.datetime_format) self.fm_date = xlwt.easyxf(num_format_str=self.date_format)
Example #2
Source File: excel.py From recruit with Apache License 2.0 | 6 votes |
def _convert_to_style(cls, style_dict, num_format_str=None): """ converts a style_dict to an xlwt style object Parameters ---------- style_dict : style dictionary to convert num_format_str : optional number format string """ import xlwt if style_dict: xlwt_stylestr = cls._style_to_xlwt(style_dict) style = xlwt.easyxf(xlwt_stylestr, field_sep=',', line_sep=';') else: style = xlwt.XFStyle() if num_format_str is not None: style.num_format_str = num_format_str return style
Example #3
Source File: excel.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def _convert_to_style(cls, style_dict, num_format_str=None): """ converts a style_dict to an xlwt style object Parameters ---------- style_dict : style dictionary to convert num_format_str : optional number format string """ import xlwt if style_dict: xlwt_stylestr = cls._style_to_xlwt(style_dict) style = xlwt.easyxf(xlwt_stylestr, field_sep=',', line_sep=';') else: style = xlwt.XFStyle() if num_format_str is not None: style.num_format_str = num_format_str return style
Example #4
Source File: excel.py From vnpy_crypto with MIT License | 6 votes |
def _convert_to_style(cls, style_dict, num_format_str=None): """ converts a style_dict to an xlwt style object Parameters ---------- style_dict: style dictionary to convert num_format_str: optional number format string """ import xlwt if style_dict: xlwt_stylestr = cls._style_to_xlwt(style_dict) style = xlwt.easyxf(xlwt_stylestr, field_sep=',', line_sep=';') else: style = xlwt.XFStyle() if num_format_str is not None: style.num_format_str = num_format_str return style
Example #5
Source File: excel.py From Computable with MIT License | 6 votes |
def _convert_to_style(cls, style_dict, num_format_str=None): """ converts a style_dict to an xlwt style object Parameters ---------- style_dict: style dictionary to convert num_format_str: optional number format string """ import xlwt if style_dict: xlwt_stylestr = cls._style_to_xlwt(style_dict) style = xlwt.easyxf(xlwt_stylestr, field_sep=',', line_sep=';') else: style = xlwt.XFStyle() if num_format_str is not None: style.num_format_str = num_format_str return style
Example #6
Source File: partners_balance_xls.py From LibrERP with GNU Affero General Public License v3.0 | 6 votes |
def print_header_titles(self, ws, _p, data, row_position, xlwtlib, _xs): cell_format = _xs['bold'] + _xs['fill_blue'] + _xs['borders_all'] cell_style = xlwtlib.easyxf(cell_format) cell_style_center = xlwtlib.easyxf(cell_format + _xs['center']) c_specs = [ ('fy', 1, 0, 'text', _('Fiscal Year'), None, cell_style_center), ('af', 1, 0, 'text', _('Accounts Filter'), None, cell_style_center), ('df', 1, 0, 'text', _p.filter_form(data) == 'filter_date' and _( 'Dates Filter') or _('Periods Filter'), None, cell_style_center), ('pf', 1, 0, 'text', _('Partners Filter'), None, cell_style_center), ('tm', 1, 0, 'text', _('Target Moves'), None, cell_style_center), ('ib', 1, 0, 'text', _('Initial Balance'), None, cell_style_center), ('coa', 1, 0, 'text', _('Chart of Account'), None, cell_style_center), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_position = self.xls_write_row( ws, row_position, row_data, row_style=cell_style) return row_position
Example #7
Source File: excel.py From elasticintel with GNU General Public License v3.0 | 6 votes |
def _convert_to_style(cls, style_dict, num_format_str=None): """ converts a style_dict to an xlwt style object Parameters ---------- style_dict: style dictionary to convert num_format_str: optional number format string """ import xlwt if style_dict: xlwt_stylestr = cls._style_to_xlwt(style_dict) style = xlwt.easyxf(xlwt_stylestr, field_sep=',', line_sep=';') else: style = xlwt.XFStyle() if num_format_str is not None: style.num_format_str = num_format_str return style
Example #8
Source File: main.py From LibrERP with GNU Affero General Public License v3.0 | 6 votes |
def from_data(self, fields, rows): workbook = xlwt.Workbook() worksheet = workbook.add_sheet('Sheet 1') for i, fieldname in enumerate(fields): worksheet.write(0, i, fieldname) worksheet.col(i).width = 8000 # around 220 pixels style = xlwt.easyxf('align: wrap yes') for row_index, row in enumerate(rows): for cell_index, cell_value in enumerate(row): if isinstance(cell_value, basestring): cell_value = re.sub("\r", " ", cell_value) if cell_value is False: cell_value = None worksheet.write(row_index + 1, cell_index, cell_value, style) fp = StringIO() workbook.save(fp) fp.seek(0) data = fp.read() fp.close() return data
Example #9
Source File: excel.py From Splunking-Crime with GNU Affero General Public License v3.0 | 6 votes |
def _convert_to_style(cls, style_dict, num_format_str=None): """ converts a style_dict to an xlwt style object Parameters ---------- style_dict: style dictionary to convert num_format_str: optional number format string """ import xlwt if style_dict: xlwt_stylestr = cls._style_to_xlwt(style_dict) style = xlwt.easyxf(xlwt_stylestr, field_sep=',', line_sep=';') else: style = xlwt.XFStyle() if num_format_str is not None: style.num_format_str = num_format_str return style
Example #10
Source File: ComplianceReportSpreadSheet.py From tfrs with Apache License 2.0 | 5 votes |
def add_exclusion_agreement(self, exclusion_agreement): worksheet = self.workbook.add_sheet("Exclusion Agreement") row_index = 0 columns = [ "Transaction Type", "Fuel Type", "Trading Partner", "Postal Address", "Quantity", "Units", "Quantity Not Sold", "Units" ] header_style = xlwt.easyxf('font: bold on') # Build Column Headers for col_index, value in enumerate(columns): worksheet.write(row_index, col_index, value, header_style) comment_format = xlwt.easyxf('align: wrap on, vert centre') date_format = xlwt.easyxf(num_format_str='yyyy-mm-dd') quantity_format = xlwt.easyxf(num_format_str='#,##0') value_format = xlwt.easyxf(num_format_str='#,##0.00') if exclusion_agreement is None: return # Build the rows for record in exclusion_agreement['records']: row_index += 1 worksheet.write(row_index, 0, record['transaction_type']) worksheet.write(row_index, 1, record['fuel_type']) worksheet.write(row_index, 2, record['transaction_partner']) worksheet.write(row_index, 3, record['postal_address']) worksheet.write(row_index, 4, Decimal(record['quantity']), quantity_format) worksheet.write(row_index, 5, record['unit_of_measure']) worksheet.write(row_index, 6, Decimal(record['quantity_not_sold']), quantity_format) worksheet.write(row_index, 7, record['unit_of_measure'])
Example #11
Source File: export.py From myblog with GNU Affero General Public License v3.0 | 5 votes |
def get_xls_export(self, context): datas = self._get_datas(context) output = io.BytesIO() export_header = ( self.request.GET.get('export_xls_header', 'off') == 'on') model_name = self.opts.verbose_name book = xlwt.Workbook(encoding='utf8') sheet = book.add_sheet( u"%s %s" % (_(u'Sheet'), force_text(model_name))) styles = {'datetime': xlwt.easyxf(num_format_str='yyyy-mm-dd hh:mm:ss'), 'date': xlwt.easyxf(num_format_str='yyyy-mm-dd'), 'time': xlwt.easyxf(num_format_str='hh:mm:ss'), 'header': xlwt.easyxf('font: name Times New Roman, color-index red, bold on', num_format_str='#,##0.00'), 'default': xlwt.Style.default_style} if not export_header: datas = datas[1:] for rowx, row in enumerate(datas): for colx, value in enumerate(row): if export_header and rowx == 0: cell_style = styles['header'] else: if isinstance(value, datetime.datetime): cell_style = styles['datetime'] elif isinstance(value, datetime.date): cell_style = styles['date'] elif isinstance(value, datetime.time): cell_style = styles['time'] else: cell_style = styles['default'] sheet.write(rowx, colx, value, style=cell_style) book.save(output) output.seek(0) return output.getvalue()
Example #12
Source File: ComplianceReportSpreadSheet.py From tfrs with Apache License 2.0 | 5 votes |
def add_schedule_a(self, schedule_a): worksheet = self.workbook.add_sheet("Schedule A") row_index = 0 columns = [ "Trading Partner", "Postal Address", "Fuel Class", "Received or Transferred", "Quantity" ] header_style = xlwt.easyxf('font: bold on') # Build Column Headers for col_index, value in enumerate(columns): worksheet.write(row_index, col_index, value, header_style) comment_format = xlwt.easyxf('align: wrap on, vert centre') date_format = xlwt.easyxf(num_format_str='yyyy-mm-dd') quantity_format = xlwt.easyxf(num_format_str='#,##0') value_format = xlwt.easyxf(num_format_str='#,##0.00') if schedule_a is None: return # Build the rows for record in schedule_a['records']: row_index += 1 worksheet.write(row_index, 0, record['trading_partner']) worksheet.write(row_index, 1, record['postal_address']) worksheet.write(row_index, 2, record['fuel_class']) worksheet.write(row_index, 3, record['transfer_type']) worksheet.write(row_index, 4, Decimal(record['quantity']), quantity_format)
Example #13
Source File: ComplianceReportSpreadSheet.py From tfrs with Apache License 2.0 | 5 votes |
def add_schedule_c(self, schedule_c): worksheet = self.workbook.add_sheet("Schedule C") row_index = 0 columns = [ "Fuel Type", "Fuel Class", "Quantity", "Units", "Expected Use", "Rationale" ] header_style = xlwt.easyxf('font: bold on') # Build Column Headers for col_index, value in enumerate(columns): worksheet.write(row_index, col_index, value, header_style) comment_format = xlwt.easyxf('align: wrap on, vert centre') date_format = xlwt.easyxf(num_format_str='yyyy-mm-dd') quantity_format = xlwt.easyxf(num_format_str='#,##0') value_format = xlwt.easyxf(num_format_str='#,##0.00') if schedule_c is None: return # Build the rows for record in schedule_c['records']: row_index += 1 worksheet.write(row_index, 0, record['fuel_type']) worksheet.write(row_index, 1, record['fuel_class']) worksheet.write(row_index, 2, Decimal(record['quantity']), quantity_format) worksheet.write(row_index, 3, record['unit_of_measure']) worksheet.write(row_index, 4, record['expected_use']) if record['rationale'] is not None: worksheet.write(row_index, 5, record['rationale'])
Example #14
Source File: export.py From django_OA with GNU General Public License v3.0 | 5 votes |
def get_xls_export(self, context): datas = self._get_datas(context) output = io.BytesIO() export_header = ( self.request.GET.get('export_xls_header', 'off') == 'on') model_name = self.opts.verbose_name book = xlwt.Workbook(encoding='utf8') sheet = book.add_sheet( u"%s %s" % (_(u'Sheet'), force_text(model_name))) styles = {'datetime': xlwt.easyxf(num_format_str='yyyy-mm-dd hh:mm:ss'), 'date': xlwt.easyxf(num_format_str='yyyy-mm-dd'), 'time': xlwt.easyxf(num_format_str='hh:mm:ss'), 'header': xlwt.easyxf('font: name Times New Roman, color-index red, bold on', num_format_str='#,##0.00'), 'default': xlwt.Style.default_style} if not export_header: datas = datas[1:] for rowx, row in enumerate(datas): for colx, value in enumerate(row): if export_header and rowx == 0: cell_style = styles['header'] else: if isinstance(value, datetime.datetime): cell_style = styles['datetime'] elif isinstance(value, datetime.date): cell_style = styles['date'] elif isinstance(value, datetime.time): cell_style = styles['time'] else: cell_style = styles['default'] sheet.write(rowx, colx, value, style=cell_style) book.save(output) output.seek(0) return output.getvalue()
Example #15
Source File: json2xls.py From json2xls with BSD 2-Clause "Simplified" License | 5 votes |
def __init__(self, xls_filename, json_data, method='get', params=None, post_data=None, headers=None, form_encoded=False, dumps=False, sheet_name='sheet0', title_style=None): self.json_dumps = partial(json.dumps, ensure_ascii=False) self.json_loads = partial(json.loads, object_pairs_hook=OrderedDict) self.sheet_name = sheet_name self.xls_filename = xls_filename self.json_data = json_data self.method = method self.params = params self.post_data = post_data self.headers = headers self.form_encoded = form_encoded self.dumps = dumps self.__check_file_suffix() self.book = Workbook(encoding='utf-8', style_compression=2) self.sheet = self.book.add_sheet(self.sheet_name) self.start_row = 0 self.title_style = xlwt.easyxf( title_style or 'font: name Arial, bold on;' 'align: vert centre, horiz center;' 'borders: top 1, bottom 1, left 1, right 1;' 'pattern: pattern solid, fore_colour lime;')
Example #16
Source File: export.py From Mxonline3 with Apache License 2.0 | 5 votes |
def get_xls_export(self, context): datas = self._get_datas(context) output = io.BytesIO() export_header = ( self.request.GET.get('export_xls_header', 'off') == 'on') model_name = self.opts.verbose_name book = xlwt.Workbook(encoding='utf8') sheet = book.add_sheet( u"%s %s" % (_(u'Sheet'), force_text(model_name))) styles = {'datetime': xlwt.easyxf(num_format_str='yyyy-mm-dd hh:mm:ss'), 'date': xlwt.easyxf(num_format_str='yyyy-mm-dd'), 'time': xlwt.easyxf(num_format_str='hh:mm:ss'), 'header': xlwt.easyxf('font: name Times New Roman, color-index red, bold on', num_format_str='#,##0.00'), 'default': xlwt.Style.default_style} if not export_header: datas = datas[1:] for rowx, row in enumerate(datas): for colx, value in enumerate(row): if export_header and rowx == 0: cell_style = styles['header'] else: if isinstance(value, datetime.datetime): cell_style = styles['datetime'] elif isinstance(value, datetime.date): cell_style = styles['date'] elif isinstance(value, datetime.time): cell_style = styles['time'] else: cell_style = styles['default'] sheet.write(rowx, colx, value, style=cell_style) book.save(output) output.seek(0) return output.getvalue()
Example #17
Source File: export.py From imoocc with GNU General Public License v2.0 | 5 votes |
def get_xls_export(self, context): datas = self._get_datas(context) output = io.BytesIO() export_header = ( self.request.GET.get('export_xls_header', 'off') == 'on') model_name = self.opts.verbose_name book = xlwt.Workbook(encoding='utf8') sheet = book.add_sheet( u"%s %s" % (_(u'Sheet'), force_text(model_name))) styles = {'datetime': xlwt.easyxf(num_format_str='yyyy-mm-dd hh:mm:ss'), 'date': xlwt.easyxf(num_format_str='yyyy-mm-dd'), 'time': xlwt.easyxf(num_format_str='hh:mm:ss'), 'header': xlwt.easyxf('font: name Times New Roman, color-index red, bold on', num_format_str='#,##0.00'), 'default': xlwt.Style.default_style} if not export_header: datas = datas[1:] for rowx, row in enumerate(datas): for colx, value in enumerate(row): if export_header and rowx == 0: cell_style = styles['header'] else: if isinstance(value, datetime.datetime): cell_style = styles['datetime'] elif isinstance(value, datetime.date): cell_style = styles['date'] elif isinstance(value, datetime.time): cell_style = styles['time'] else: cell_style = styles['default'] sheet.write(rowx, colx, value, style=cell_style) book.save(output) output.seek(0) return output.getvalue()
Example #18
Source File: export.py From devops with MIT License | 5 votes |
def get_xls_export(self, context): datas = self._get_datas(context) output = StringIO.StringIO() export_header = ( self.request.GET.get('export_xls_header', 'off') == 'on') model_name = self.opts.verbose_name book = xlwt.Workbook(encoding='utf8') sheet = book.add_sheet( u"%s %s" % (_(u'Sheet'), force_str(model_name))) styles = {'datetime': xlwt.easyxf(num_format_str='yyyy-mm-dd hh:mm:ss'), 'date': xlwt.easyxf(num_format_str='yyyy-mm-dd'), 'time': xlwt.easyxf(num_format_str='hh:mm:ss'), 'header': xlwt.easyxf('font: name Times New Roman, color-index red, bold on', num_format_str='#,##0.00'), 'default': xlwt.Style.default_style} if not export_header: datas = datas[1:] for rowx, row in enumerate(datas): for colx, value in enumerate(row): if export_header and rowx == 0: cell_style = styles['header'] else: if isinstance(value, datetime.datetime): cell_style = styles['datetime'] elif isinstance(value, datetime.date): cell_style = styles['date'] elif isinstance(value, datetime.time): cell_style = styles['time'] else: cell_style = styles['default'] sheet.write(rowx, colx, value, style=cell_style) book.save(output) output.seek(0) return output.getvalue()
Example #19
Source File: export.py From online with GNU Affero General Public License v3.0 | 5 votes |
def get_xls_export(self, context): datas = self._get_datas(context) output = io.BytesIO() export_header = ( self.request.GET.get('export_xls_header', 'off') == 'on') model_name = self.opts.verbose_name book = xlwt.Workbook(encoding='utf8') sheet = book.add_sheet( u"%s %s" % (_(u'Sheet'), force_text(model_name))) styles = {'datetime': xlwt.easyxf(num_format_str='yyyy-mm-dd hh:mm:ss'), 'date': xlwt.easyxf(num_format_str='yyyy-mm-dd'), 'time': xlwt.easyxf(num_format_str='hh:mm:ss'), 'header': xlwt.easyxf('font: name Times New Roman, color-index red, bold on', num_format_str='#,##0.00'), 'default': xlwt.Style.default_style} if not export_header: datas = datas[1:] for rowx, row in enumerate(datas): for colx, value in enumerate(row): if export_header and rowx == 0: cell_style = styles['header'] else: if isinstance(value, datetime.datetime): cell_style = styles['datetime'] elif isinstance(value, datetime.date): cell_style = styles['date'] elif isinstance(value, datetime.time): cell_style = styles['time'] else: cell_style = styles['default'] sheet.write(rowx, colx, value, style=cell_style) book.save(output) output.seek(0) return output.getvalue()
Example #20
Source File: export.py From Dailyfresh-B2C with Apache License 2.0 | 5 votes |
def get_xls_export(self, context): datas = self._get_datas(context) output = io.BytesIO() export_header = ( self.request.GET.get('export_xls_header', 'off') == 'on') model_name = self.opts.verbose_name book = xlwt.Workbook(encoding='utf8') sheet = book.add_sheet( u"%s %s" % (_(u'Sheet'), force_text(model_name))) styles = {'datetime': xlwt.easyxf(num_format_str='yyyy-mm-dd hh:mm:ss'), 'date': xlwt.easyxf(num_format_str='yyyy-mm-dd'), 'time': xlwt.easyxf(num_format_str='hh:mm:ss'), 'header': xlwt.easyxf('font: name Times New Roman, color-index red, bold on', num_format_str='#,##0.00'), 'default': xlwt.Style.default_style} if not export_header: datas = datas[1:] for rowx, row in enumerate(datas): for colx, value in enumerate(row): if export_header and rowx == 0: cell_style = styles['header'] else: if isinstance(value, datetime.datetime): cell_style = styles['datetime'] elif isinstance(value, datetime.date): cell_style = styles['date'] elif isinstance(value, datetime.time): cell_style = styles['time'] else: cell_style = styles['default'] sheet.write(rowx, colx, value, style=cell_style) book.save(output) output.seek(0) return output.getvalue()
Example #21
Source File: export.py From ImitationTmall_Django with GNU General Public License v3.0 | 5 votes |
def get_xls_export(self, context): datas = self._get_datas(context) output = StringIO.StringIO() export_header = ( self.request.GET.get('export_xls_header', 'off') == 'on') model_name = self.opts.verbose_name book = xlwt.Workbook(encoding='utf8') sheet = book.add_sheet( u"%s %s" % (_(u'Sheet'), force_unicode(model_name))) styles = {'datetime': xlwt.easyxf(num_format_str='yyyy-mm-dd hh:mm:ss'), 'date': xlwt.easyxf(num_format_str='yyyy-mm-dd'), 'time': xlwt.easyxf(num_format_str='hh:mm:ss'), 'header': xlwt.easyxf('font: name Times New Roman, color-index red, bold on', num_format_str='#,##0.00'), 'default': xlwt.Style.default_style} if not export_header: datas = datas[1:] for rowx, row in enumerate(datas): for colx, value in enumerate(row): if export_header and rowx == 0: cell_style = styles['header'] else: if isinstance(value, datetime.datetime): cell_style = styles['datetime'] elif isinstance(value, datetime.date): cell_style = styles['date'] elif isinstance(value, datetime.time): cell_style = styles['time'] else: cell_style = styles['default'] sheet.write(rowx, colx, value, style=cell_style) book.save(output) output.seek(0) return output.getvalue()
Example #22
Source File: power_deviation_matrix.py From PCWG with MIT License | 5 votes |
def __init__(self, power_deviaiton_matrix_dimensions): self.calculated_power_deviation_matrix_dimensions = power_deviaiton_matrix_dimensions self.bold_style = xlwt.easyxf('font: bold 1') self.rotated_bold_style = xlwt.easyxf('align: rotation 90; font: bold 1') self.one_dp_style = xlwt.easyxf(num_format_str='0.0') self.percent_no_dp_style = xlwt.easyxf(num_format_str='0%')
Example #23
Source File: share_matrix_report.py From PCWG with MIT License | 5 votes |
def __init__(self): self.normal_style = xlwt.easyxf('font: bold 0') self.bold_style = xlwt.easyxf('font: bold 1') self.no_dp_style = xlwt.easyxf(num_format_str='0') self.one_dp_style = xlwt.easyxf(num_format_str='0.0') self.two_dp_style = xlwt.easyxf(num_format_str='0.00') self.three_dp_style = xlwt.easyxf(num_format_str='0.000') self.four_dp_style = xlwt.easyxf(num_format_str='0.0000') self.percent_style = xlwt.easyxf(num_format_str='0.00%') self.percent_no_dp_style = xlwt.easyxf(num_format_str='0%') self.book = xlwt.Workbook() self.gradient = ColourGradient(-0.1, 0.1, 0.01, self.book)
Example #24
Source File: data_sharing_reports.py From PCWG with MIT License | 5 votes |
def __init__(self): self.bold_style = xlwt.easyxf('font: bold 1') self.no_dp_style = xlwt.easyxf(num_format_str='0') self.one_dp_style = xlwt.easyxf(num_format_str='0.0') self.two_dp_style = xlwt.easyxf(num_format_str='0.00') self.three_dp_style = xlwt.easyxf(num_format_str='0.000') self.four_dp_style = xlwt.easyxf(num_format_str='0.0000') self.percent_style = xlwt.easyxf(num_format_str='0.00%') self.percent_no_dp_style = xlwt.easyxf(num_format_str='0%')
Example #25
Source File: _excel.py From pytablewriter with MIT License | 5 votes |
def __get_cell_style(self, col: int): try: import xlwt except ImportError: warnings.warn(import_error_msg_template.format("excel")) raise if col in self.__col_style_table: return self.__col_style_table.get(col) try: col_dp = self._column_dp_list[col] except KeyError: return {} if col_dp.typecode not in [typepy.Typecode.REAL_NUMBER]: raise ValueError() if not Integer(col_dp.minmax_decimal_places.max_value).is_type(): raise ValueError() float_digit = col_dp.minmax_decimal_places.max_value if float_digit <= 0: raise ValueError() num_format_str = "#,{:s}0.{:s}".format("#" * int(float_digit), "0" * int(float_digit)) cell_style = xlwt.easyxf(num_format_str=num_format_str) self.__col_style_table[col] = cell_style return cell_style
Example #26
Source File: export.py From CTF_AWD_Platform with MIT License | 5 votes |
def get_xls_export(self, context): datas = self._get_datas(context) output = io.BytesIO() export_header = ( self.request.GET.get('export_xls_header', 'off') == 'on') model_name = self.opts.verbose_name book = xlwt.Workbook(encoding='utf8') sheet = book.add_sheet( u"%s %s" % (_(u'Sheet'), force_text(model_name))) styles = {'datetime': xlwt.easyxf(num_format_str='yyyy-mm-dd hh:mm:ss'), 'date': xlwt.easyxf(num_format_str='yyyy-mm-dd'), 'time': xlwt.easyxf(num_format_str='hh:mm:ss'), 'header': xlwt.easyxf('font: name Times New Roman, color-index red, bold on', num_format_str='#,##0.00'), 'default': xlwt.Style.default_style} if not export_header: datas = datas[1:] for rowx, row in enumerate(datas): for colx, value in enumerate(row): if export_header and rowx == 0: cell_style = styles['header'] else: if isinstance(value, datetime.datetime): cell_style = styles['datetime'] elif isinstance(value, datetime.date): cell_style = styles['date'] elif isinstance(value, datetime.time): cell_style = styles['time'] else: cell_style = styles['default'] sheet.write(rowx, colx, value, style=cell_style) book.save(output) output.seek(0) return output.getvalue()
Example #27
Source File: search.py From coursys with GNU General Public License v3.0 | 5 votes |
def _generate_excel(response, columns, headers, grads): import xlwt book = xlwt.Workbook(encoding='utf-8') sheet = book.add_sheet('Search Results') hdrstyle = xlwt.easyxf('font: bold on; pattern: pattern solid, fore_colour grey25; align: horiz centre') evenstyle = xlwt.easyxf('pattern: back_colour gray40') oddstyle = xlwt.easyxf('pattern: pattern sparse_dots, fore_colour grey25') # header row sheet.write(0, 0, 'Graduate Student Search Results', xlwt.easyxf('font: bold on, height 320')) sheet.row(0).height = 400 for i,hdr in enumerate(headers): sheet.write(1, i, hdr, hdrstyle) # data rows for i,grad in enumerate(grads): style = [oddstyle, evenstyle][i%2] for j,column in enumerate(columns): sheet.write(i+2, j, getattribute(grad, column, html=False), style) # set column widths for i,c in enumerate(columns): wid = COLUMN_WIDTHS[c] sheet.col(i).width = wid count = len(grads) sheet.write(count+4, 0, 'Number of students: %i' % (count)) sheet.write(count+5, 0, 'Report generated: %s' % (datetime.datetime.now())) book.save(response)
Example #28
Source File: export.py From StormOnline with Apache License 2.0 | 5 votes |
def get_xls_export(self, context): datas = self._get_datas(context) output = io.BytesIO() export_header = ( self.request.GET.get('export_xls_header', 'off') == 'on') model_name = self.opts.verbose_name book = xlwt.Workbook(encoding='utf8') sheet = book.add_sheet( u"%s %s" % (_(u'Sheet'), force_text(model_name))) styles = {'datetime': xlwt.easyxf(num_format_str='yyyy-mm-dd hh:mm:ss'), 'date': xlwt.easyxf(num_format_str='yyyy-mm-dd'), 'time': xlwt.easyxf(num_format_str='hh:mm:ss'), 'header': xlwt.easyxf('font: name Times New Roman, color-index red, bold on', num_format_str='#,##0.00'), 'default': xlwt.Style.default_style} if not export_header: datas = datas[1:] for rowx, row in enumerate(datas): for colx, value in enumerate(row): if export_header and rowx == 0: cell_style = styles['header'] else: if isinstance(value, datetime.datetime): cell_style = styles['datetime'] elif isinstance(value, datetime.date): cell_style = styles['date'] elif isinstance(value, datetime.time): cell_style = styles['time'] else: cell_style = styles['default'] sheet.write(rowx, colx, value, style=cell_style) book.save(output) output.seek(0) return output.getvalue()
Example #29
Source File: excel_export.py From kansha with BSD 3-Clause "New" or "Revised" License | 5 votes |
def write(self): sty = '' header_sty = xlwt.easyxf(sty + 'font: bold on; align: wrap on, vert centre, horiz center;') sty = xlwt.easyxf(sty) ws = self.workbook.add_sheet(self.sheet_name) titles = [_(u'Column'), _(u'Title')] + self.extension_titles for col, title in enumerate(titles): ws.write(0, col, title, style=header_sty) row = 1 for column in self.board.columns: column = column() colname = _('Archived cards') if column.is_archive else column.get_title() for card in column.cards: card = card() ws.write(row, 0, colname, sty) ws.write(row, 1, card.get_title(), sty) card_extensions = dict(card.extensions) for col, key in enumerate(self.extensions, 2): ext = card_extensions[key]() write_extension_data(ext, ws, row, col, sty) row += 1 for col in xrange(len(titles)): ws.col(col).width = 0x3000 ws.set_panes_frozen(True) ws.set_horz_split_pos(1)
Example #30
Source File: partners_balance_xls.py From LibrERP with GNU Affero General Public License v3.0 | 5 votes |
def print_title(self, ws, _p, row_position, xlwtlib, _xs): cell_style = xlwtlib.easyxf(_xs['xls_title']) report_name = ' - '.join([_p.report_name.upper(), _p.company.partner_id.name, _p.company.currency_id.name]) c_specs = [ ('report_name', 1, 0, 'text', report_name), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_position = self.xls_write_row( ws, row_position, row_data, row_style=cell_style) return row_position