2016-06-21 3 views
1

이 예 (http://xlsxwriter.readthedocs.io/working_with_conditional_formats.html)에 따라 열의 색 눈금을 사용할 수 있습니다.xlsxwriter의 전체 열에 색상 스케일을 사용하는 방법

워드 프로세서 예 :

caption = 'Examples of color scales and data bars. Default colors.' 

data = range(1, 13) 
worksheet7.write('A1', caption) 
worksheet7.write('B2', "3 Color Scale") 

for row, row_data in enumerate(data): 
    worksheet7.write(row + 2, 1, row_data) 

worksheet7.conditional_format('B3:B14', {'type': '3_color_scale'}) 

당신은 내가없이 그것의 전체 B 열에 포맷을 적용 할 포맷이 제 1의 소정의 B 칼럼 영역에 적용되는 것을 볼 수있다 길이.

나는이 작업을 수행 할 때 :

caption = 'Examples of color scales and data bars. Default colors.' 

data = range(1, 13) 
worksheet7.write('A1', caption) 
worksheet7.write('B2', "3 Color Scale") 

for row, row_data in enumerate(data): 
    worksheet7.write(row + 2, 1, row_data) 

worksheet7.conditional_format('B:B', {'type': '3_color_scale'}) 
# or this worksheet7.conditional_format('$B:$B', {'type': '3_color_scale'}) 

나는 다음과 같은 오류 얻을 :

File "build\bdist.win-amd64\egg\xlsxwriter\worksheet.py", line 85, in cell_wrapper 
    File "build\bdist.win-amd64\egg\xlsxwriter\utility.py", line 108, in xl_cell_to_rowcol 
AttributeError: 'NoneType' object has no attribute 'group' 

이 작업을 수행하는 적절한 방법은 무엇입니까?

답변

1

일반적으로 XlsxWriter에서 최대 열 값으로 2D 범위를 설정하여 Col:Col 스타일 범위를 얻을 수 있습니다. 이것은 (일반적으로) Excel에서 내부적으로 발생하는 것입니다.

그래서 다음은 귀하의 경우에 작동합니다 :

worksheet7.conditional_format('B1:B1048576', {'type': '3_color_scale'}) 

# Or with row, col notation: 
worksheet7.conditional_format(1, 0, 1048575, 1, {'type': '2_color_scale'}) 

엑셀 내에서 범위는 B:B로 표시됩니다.

+0

감사합니다. 이것이 어떤 방식 으로든 성능에 영향을 줍니까? 엑셀 세대가 더 느린 걸까? –

+1

XlsxWriter의 성능에 영향을 미치지 않으며 파일 생성 속도가 느리지 않습니다. – jmcnamara