파이썬에서 엑셀 read/write 하기 + Azure CLI와 같이 활용!

2022. 5. 24. 17:16·System Engineering/파이썬
from openpyxl import load_workbook


# data_only=Ture로 해줘야 수식이 아닌 값으로 받아온다.
load_wb = load_workbook(
    "/Users/hojaelee/desktop/powershell/gather_metric.xlsx", data_only=True)

# 시트 이름으로 불러오기
load_ws = load_wb['Metrics']


#셀 주소에 갑 입력
load_ws['C5'] = 6666

# 셀 주소로 값 출력
print(load_ws['A1'].value)

# 셀 좌표로 값 출력
print(load_ws.cell(1, 2).value)


load_wb.save("/Users/hojaelee/desktop/powershell/gather_metric.xlsx")

 

참고)

이건 기존에 엑셀이 존재할 때.

 

그래서 import를 load_workbook만 한거야.

새롭게 엑셀 파일을 생성하고 싶으면 Workbook을 import 해야돼.

 

주의!)

반드시 마지막에 엑셀에 저장을 해줘야돼. 안그러면 저장이 안돼. 이것 때문에 몇 시간 헤맸어.

 

-> Azure CLI와 같이 활용해서 Automation할 때 쓰면 좋아.

 

https://openpyxl.readthedocs.io/en/stable/

 

openpyxl - A Python library to read/write Excel 2010 xlsx/xlsm files — openpyxl 3.0.10 documentation

Install openpyxl using pip. It is advisable to do this in a Python virtualenv without system packages: Warning To be able to include images (jpeg, png, bmp,…) into an openpyxl file, you will also need the “pillow” library that can be installed with:

openpyxl.readthedocs.io

 

저작자표시 비영리 (새창열림)

'System Engineering > 파이썬' 카테고리의 다른 글

VSCODE : Python could not be resolved from source Pylance 에러 (가상 환경 인터프리터 선택)  (0) 2022.06.06
os.popen()과 system.os()의 차이  (0) 2022.05.24
파이썬 스크립트 - TechCrunch Scraper  (0) 2022.03.24
6줄 코드 날씨 API  (0) 2022.03.24
udemy 100일 부트캠프  (0) 2022.01.19
'System Engineering/파이썬' 카테고리의 다른 글
  • VSCODE : Python could not be resolved from source Pylance 에러 (가상 환경 인터프리터 선택)
  • os.popen()과 system.os()의 차이
  • 파이썬 스크립트 - TechCrunch Scraper
  • 6줄 코드 날씨 API
Hojae Lee
Hojae Lee
Solutions Architect
  • Hojae Lee
    기억력이 금붕어라
    Hojae Lee
  • 전체
    오늘
    어제
  • 공지사항

    • 참고사항
    • 이 블로그를 잘 활용하는 방법
    • my linkedin
    • 분류 전체보기 (413) N
      • Career Path (19)
        • My Achievements (10)
        • About Career (1)
      • Projects for $100 (1)
      • CLOUD (185) N
        • AWS Cloud (122) N
        • Azure Cloud (61)
      • System Engineering (90)
        • Kubernetes (47)
        • 파이썬 (7)
        • Docker (0)
        • System Design (4)
        • DevOps (2)
        • SRE (5)
        • git (1)
        • 리눅스, 라즈베리파이 (17)
        • Powershell (2)
      • Computer Science (71) N
        • Operating System (22)
        • Computer Architecture (5)
        • Network (18)
        • Database (14) N
        • Security (9)
        • Machine Learning, AI (1)
      • Cloud Webinar (4)
        • AWS Summit (4)
      • 3D 프린터 (1)
      • IaC (4)
        • CloudFormation (0)
        • Terraform (4)
      • 아두이노 (임베디드) (2)
      • 개발자의 전기 전자 공부 (3)
      • 이전 직장 (11)
        • TMAX Soft (11)
      • 작업 환경 셋업 (3)
  • 최근 댓글

  • hELLO· Designed By정상우.v4.10.3
Hojae Lee
파이썬에서 엑셀 read/write 하기 + Azure CLI와 같이 활용!
상단으로

티스토리툴바