반응형
패키지 설치합니다.
pip install openpyxl
특정 엑셀에 B열에 있는 셀서식을 모두 숫자형식으로 바꾸고 싶었습니다.
그래서 아래와 같은 코드가 탄생했습니다.
from openpyxl import Workbook, load_workbook
from openpyxl.styles import numbers
from openpyxl import Workbook
excel = r"C:\Users\consolework\Downloads\엑셀합치기결과_20230602163911.xlsx"
# Load the workbook
workbook = load_workbook(excel)
sheet = workbook.active
# Change the format of cells from B2 to the end of column B
for row in sheet.iter_rows(min_row=2, min_col=2, max_col=2):
for cell in row:
# cell.number_format = "@" # Set the format to string
cell.number_format = numbers.FORMAT_NUMBER
# Save the workbook
workbook.save(excel)
numbers. 자료안에 있는 포맷들을 바꾸어가면서 포맷 설정이 가능합니다.
반응형
'프로그래밍 > python' 카테고리의 다른 글
| [PyQt, PySide6] 프로그램 실행 시 로그인 기능 구현하기 (0) | 2023.06.05 |
|---|---|
| python PySide6 QTableWidget 열 크기 맞추기 (0) | 2023.06.05 |
| 파이썬 엑셀 파일 합치는 프로그램 (0) | 2023.06.02 |
| python selector xpath 크롬 콘솔에서 테스트방법 (0) | 2023.06.01 |
| python html에서 원하는 태그만 추출하기 (0) | 2023.05.31 |