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()
' 속성이 없다는 오류가 표시됩니다.
.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] 삭제
몇 마디 만하겠습니다