Python openpyxl.utils.get_column_letter() Examples

The following are 5 code examples of openpyxl.utils.get_column_letter(). 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 openpyxl.utils , or try the search function .
Example #1
Source File: columns.py    From openpyxl-templates with MIT License 6 votes vote down vote up
def column_letter(self):
        return get_column_letter(self.column_index) 
Example #2
Source File: bloodhoundanalytics.py    From BloodHound-Tools with GNU Lesser General Public License v3.0 5 votes vote down vote up
def save_workbook(self):
		for worksheet in self.workbook._sheets:
			for col in worksheet.columns:
				max_length = 0
				column = get_column_letter(col[0].column)  # Get the column name
				for cell in col:
					try:  # Necessary to avoid error on empty cells
						if len(str(cell.value)) > max_length:
							max_length = len(cell.value)
					except:
						pass
				adjusted_width = (max_length + 2) * 1.2
				worksheet.column_dimensions[column].width = adjusted_width
		self.workbook.save(self.filename) 
Example #3
Source File: sheet1.py    From OverwatchDataAnalysis with GNU General Public License v3.0 5 votes vote down vote up
def _set_cells_style(self):
        """
        将样式应用到所有 cell 中 
        """
        max_row, max_column = self.sheet.max_row + 1, self.sheet.max_column + 1
        for r in range(1, max_row):
            self.sheet.row_dimensions[r].height = Config.cell_height
            for c in range(1, max_column):
                letter = get_column_letter(c)
                title = letter + str(r)
                self._set_cell_style(self.sheet[title], title)
                self.sheet.column_dimensions[letter].width = Config.cell_width[letter] 
Example #4
Source File: read_only.py    From vnpy_crypto with MIT License 4 votes vote down vote up
def coordinate(self):
        column = get_column_letter(self.column)
        return "{1}{0}".format(self.row, column) 
Example #5
Source File: excel.py    From Attendance-Management-using-Face-Recognition with GNU General Public License v3.0 4 votes vote down vote up
def createWorksheet(wb):
    # "creating register"
    global NAMES, ROLLS, NUMBER_OF_STUDENTS
    manth = month()
    ws = wb.create_sheet(manth)
    ws.merge_cells('A1:AN2')
    heading = 'Attendance Record for ' + manth
    heading = heading + ' ' * 50 + heading + ' ' * 50 + heading
    ws['A1'] = heading
    ws['A1'].font = HEADING_FONT
    ws['A1'].alignment = ALIGNMENT

    # ws.sheet_properties.tabColor = 'FFFF66'
    ws['A3'] = 'S.No'
    ws['B3'] = 'Enrollment'
    ws['B3'].fill = FILL_ROLL
    ws.merge_cells('C3:D3')
    ws['C3'] = 'Name'
    ws['C3'].fill = FILL_NAME

    cellrange = 'A' + str(GAP - 1) + ':AN' + str(GAP - 1)
    set_border(ws, cellrange)
    for i in range(NUMBER_OF_STUDENTS):
        ws.merge_cells(start_row=GAP + i, start_column=3, end_row=GAP + i, end_column=4)
        ws.cell(row=GAP + i, column=1, value=str(i + 1))
        ws.cell(row=GAP + i, column=2, value=ROLLS[i]).fill = FILL_ROLL
        ws.cell(row=GAP + i, column=3, value=NAMES[i]).fill = FILL_NAME

        cellrange = 'A' + str(GAP + i) + ':AN' + str(GAP + i)
        set_border(ws, cellrange)
    today = todays_date()
    first_day = date(today.year, today.month, 1)
    days_in_month = monthrange(today.year, today.month)[1]
    for i in range(days_in_month):
        dt = first_day + timedelta(days=i)
        ws.cell(row=3, column=DATE_COLUMN + i, value=dt).fill = FILL_DATE

    first_date_column = get_column_letter(DATE_COLUMN)
    last_date_column = get_column_letter(DATE_COLUMN + days_in_month - 1)
    sum_cell_column = DATE_COLUMN + days_in_month + 1
    ws.cell(row=3, column=sum_cell_column, value="Total").fill = FILL_TOTAL
    for i in range(NUMBER_OF_STUDENTS):
        ws.cell(row=GAP + i, column=sum_cell_column,
                value="=SUM(" + first_date_column + str(GAP + i) + ":" + last_date_column + str(
                    GAP + i) + ")").fill = FILL_TOTAL