openpyxl 및 python3을 사용하여 Excel 워크 시트의 셀 범위 (열 및 행)에 글꼴 색상을 지정하는 방법은 무엇입니까?

아 비랄 스리 바스타 바

Excel 시트에서 일련의 셀 (한 열에서 다른 열로)에 빨간색을 설정하고 openpyxl.

공식 문서에서 셀에 특정 색상을 부여하는 방법을 찾을 수 있었지만 범위를 지정하는 방법을 알 수 없었습니다.

기본적으로 openpyxl을 사용하여 다음과 같은 것을 원합니다.

inheritance_cell_format = wb.add_format()
inheritance_cell_format.set_font_color('red')
ws.conditional_format( 0, skip_cols-2, ws.max_row, skip_cols-1, { 'type': 'cell', 'criteria': '=', 'value': '⇒', 'format': inheritance_cell_format } )

위의 스 니펫은 xlsxwriter에서 작동합니다.

현재로서는 분명히 첫 줄에 통합 문서에 ' add_format()' 속성이 없다는 오류가 표시됩니다.

파블로 I. 오초아

.iter_rows () 또는 iter_cols () 메소드를 사용하여 루프로 범위에 색상을 지정할 수 있습니다. PatternFill을 가져와 색상을 지정할 수 있습니다.

import openpyxl as px
from openpyxl.styles import PatternFill

wb = px.load_workbook(file) #imports file
ws = wb.active #Active sheet (first one)
for row in sheet.iter_rows(min_row=1, max_col=3, max_row=2): #max row and col (range)
   for cell in row:
       cell.fill = PatternFill(start_color="FF0000", fill_type = "solid") #html colors


wb.save(file)

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Related 관련 기사

뜨겁다태그

보관