How to use the openpyxl.cell.get_column_letter function in openpyxl

To help you get started, we’ve selected a few openpyxl examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jmcnamara / XlsxWriter / dev / performance / bench_excel_writers.py View on Github external
def time_openpyxl():
    """ Run OpenPyXL in default mode. """
    start_time = clock()

    workbook = openpyxl.workbook.Workbook()
    worksheet = workbook.active

    for row in range(row_max // 2):
        for col in range(col_max):
            colletter = get_column_letter(col + 1)
            worksheet.cell('%s%s' % (colletter, row * 2 + 1)).value = "Row: %d Col: %d" % (row, col)
        for col in range(col_max):
            colletter = get_column_letter(col + 1)
            worksheet.cell('%s%s' % (colletter, row * 2 + 2)).value = row + col

    workbook.save('openpyxl.xlsx')

    elapsed = clock() - start_time
    print_elapsed_time('openpyxl', elapsed)
github ericgazoni / openpyxl / openpyxl / worksheet.py View on Github external
:type row: int

        :param column: number of columns to offset
        :type column: int

        :rtype: tuples of tuples of :class:`openpyxl.cell.Cell`

        """
        if ':' in range_string:
            # R1C1 range
            result = []
            min_range, max_range = range_string.split(':')
            min_col, min_row = coordinate_from_string(min_range)
            max_col, max_row = coordinate_from_string(max_range)
            if column:
                min_col = get_column_letter(
                        column_index_from_string(min_col) + column)
                max_col = get_column_letter(
                        column_index_from_string(max_col) + column)
            min_col = column_index_from_string(min_col)
            max_col = column_index_from_string(max_col)
            cache_cols = {}
            for col in xrange(min_col, max_col + 1):
                cache_cols[col] = get_column_letter(col)
            rows = xrange(min_row + row, max_row + row + 1)
            cols = xrange(min_col, max_col + 1)
            for row in rows:
                new_row = []
                for col in cols:
                    new_row.append(self.cell('%s%s' % (cache_cols[col], row)))
                result.append(tuple(new_row))
            return tuple(result)
github mkasa / json2xlsx / json2xlsx / utilities / json2xlsx.py View on Github external
def set_column_width_if_needed(worksheet, column, width_style):
    if width_style == None: return
    worksheet.column_dimensions[openpyxl.cell.get_column_letter(column + 1)].width = width_style
github flika-org / flika / plugins / detect_puffs / average_origin.py View on Github external
def export(self,filename):
        ''' This function saves out all the info about the puffs        
        '''
        from openpyxl import Workbook
        from openpyxl.cell import get_column_letter
        g.m.statusBar().showMessage('Saving {}'.format(os.path.basename(filename)))
        
        workbook = Workbook() 
        sheet = workbook.create_sheet()
        sheet.title="Puff Data"
        header=['Group #','Group x','Group y','No. Events','Max Amp','x','y','t_peak','Amplitude','sigmax','sigmay','angle','r20','r50','r80','r100','f80','f50','f20','f0']
        for j in np.arange(len(header)):
            col = get_column_letter(j+1)
            sheet.cell("{}{}".format(col,1)).value=header[j]
        row=2
        groupN=1
        for site in self.sites:
            r=str(row)
            groupx,groupy=site.pos
            nEvents=len(site.puffs)
            maxAmp=np.max([puff.kinetics['amplitude'] for puff in site.puffs])
            sheet.cell('A'+r).value=groupN
            sheet.cell('B'+r).value=groupx
            sheet.cell('C'+r).value=groupy
            sheet.cell('D'+r).value=nEvents
            sheet.cell('E'+r).value=maxAmp
            for puff in site.puffs:
                r=str(row)
                k=puff.kinetics
github CarlKing5019 / python3-cookbook-personal / basic / samples / excel / generate_schema.py View on Github external
def write_xlsx():
    wb = Workbook()
    dest_filename = 'empty_book.xlsx'
    ws = wb.active
    ws.title = "首页列表"
    for col_idx in range(1, 10):
        col = get_column_letter(col_idx)
        for row in range(1, 20):
            ws['%s%s' % (col, row)].value = '%s%s' % (col, row)
    ws.merge_cells('A1:B1')  # 合并单元格
    ws.unmerge_cells('A1:B1')
    ws = wb.create_sheet()
    ws.title = 'Pi'
    ws['F5'] = 3.14
    # img = Image('logo.png')
    # img.drawing.top = 100
    # img.drawing.left = 150

    wb.save(filename=dest_filename)

    wb = load_workbook(filename='empty_book.xlsx')
    sheet_ranges = wb['首页列表']
    print(sheet_ranges['D18'].value)
github ericgazoni / openpyxl / openpyxl / worksheet / worksheet.py View on Github external
def point_pos(self, left=0, top=0):
        """ tells which cell is under the given coordinates (in pixels)
        counting from the top-left corner of the sheet.
        Can be used to locate images and charts on the worksheet """
        current_col = 1
        current_row = 1
        column_dimensions = self.column_dimensions
        row_dimensions = self.row_dimensions
        default_width = points_to_pixels(DEFAULT_COLUMN_WIDTH)
        default_height = points_to_pixels(DEFAULT_ROW_HEIGHT)
        left_pos = 0
        top_pos = 0

        while left_pos <= left:
            letter = get_column_letter(current_col)
            current_col += 1
            if letter in column_dimensions:
                cdw = column_dimensions[letter].width
                if cdw > 0:
                    left_pos += points_to_pixels(cdw)
                    continue
            left_pos += default_width

        while top_pos <= top:
            row = current_row
            current_row += 1
            if row in row_dimensions:
                rdh = row_dimensions[row].height
                if rdh > 0:
                    top_pos += points_to_pixels(rdh)
                    continue
github pcolmant / repanier / repanier / admin_export_xlsx.py View on Github external
c.style.number_format.format_code = row[col_num][ ROW_FORMAT ]
			if row[col_num][ ROW_BOX ]:
				c.style.borders.top.border_style = Border.BORDER_THIN
				c.style.borders.bottom.border_style = Border.BORDER_THIN
				c.style.borders.left.border_style = Border.BORDER_THIN
				c.style.borders.right.border_style = Border.BORDER_THIN
			else:
				c.style.borders.bottom.border_style = Border.BORDER_HAIR
			if col_num == 7:
				c.style.font.bold = True

		row_num += 1

	if wb != None:
		if hidde_column_vat:
			ws.column_dimensions[get_column_letter(9)].visible = False
		if hidde_column_compensation:
			ws.column_dimensions[get_column_letter(10)].visible = False

		current_site_name = Site.objects.get_current().name
		for col_num in xrange(11):
			c = ws.cell(row=row_num, column=col_num)
			c.style.borders.top.border_style = Border.BORDER_THIN
			c.style.borders.bottom.border_style = Border.BORDER_THIN
			if col_num == 1:
				c.value = unicode(_("Total Price")) + " " + current_site_name
				# c.style.font.bold = True
			if col_num == 7:
				formula = 'SUM(H%s:H%s)' % (2, row_num)
				c.value = '=' + formula
				c.style.number_format.format_code = u'_ € * #,##0.00_ ;_ € * -#,##0.00_ ;_ € * "-"??_ ;_ @_ '
				c.style.font.bold = True
github ericgazoni / openpyxl / openpyxl / worksheet / iter_worksheet.py View on Github external
def get_squared_range(self, min_col, min_row, max_col, max_row):
        """
        The source worksheet file may have columns or rows missing.
        Missing cells will be created.
        """
        if max_col is not None:
            expected_columns = [get_column_letter(ci) for ci in xrange(min_col, max_col)]
        else:
            expected_columns = []
        row_counter = min_row

        # get cells row by row
        for row, cells in groupby(self.get_cells(min_row, min_col,
                                                 max_row, max_col),
                                  operator.attrgetter('row')):
            full_row = []
            if row_counter < row:
                # Rows requested before those in the worksheet
                for gap_row in xrange(row_counter, row):
                    yield tuple(EMPTY_CELL for column in expected_columns)
                    row_counter = row

            if expected_columns:
github ericgazoni / openpyxl / openpyxl / writer / dump_worksheet.py View on Github external
def get_dimensions(self):
        if not self._max_col or not self._max_row:
            return 'A1'
        else:
            return '%s%d' % (get_column_letter(self._max_col), (self._max_row))
github pcolmant / repanier / repanier / admin_export_xlsx.py View on Github external
col_num = len(row)
				q_min = offer_item.product.customer_minimum_order_quantity
				q_alert = offer_item.product.customer_alert_order_quantity
				q_step = offer_item.product.customer_increment_order_quantity
				# The q_min cannot be 0. In this case try to replace q_min by q_step.
				# In last ressort by q_alert.
				if q_step <= 0:
					q_step = q_min
				if q_min <= 0:
					q_min = q_step
				if q_min <= 0:
					q_min = q_alert
					q_step = q_alert
				c = ws.cell(row=row_num, column=col_num)
				c.value = unicode('---')
				ws.column_dimensions[get_column_letter(col_num+1)].width = 2.3
				c.style.number_format.format_code = NumberFormat.FORMAT_TEXT
				col_num += 1
				q_valid = q_min
				q_counter = 0 # Limit to avoid too long selection list
				while q_valid <= q_alert and q_counter <= 20:
					q_counter += 1
					c = ws.cell(row=row_num, column=col_num)
					c.value = get_qty_display(
						q_valid,
					 	offer_item.product.order_average_weight,
						offer_item.product.order_unit
					)
					ws.column_dimensions[get_column_letter(col_num+1)].width = 15
					c.style.number_format.format_code = NumberFormat.FORMAT_TEXT
					col_num += 1
					if q_valid < q_step: