Skip to content

Instantly share code, notes, and snippets.

@fereria
Created August 21, 2015 11:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fereria/cfe123d291f08731eb3f to your computer and use it in GitHub Desktop.
Save fereria/cfe123d291f08731eb3f to your computer and use it in GitHub Desktop.
Excel Python Test
## -*- coding: utf-8 -*-
import win32com.client as win32
#COMを利用して、Excelに接続
xlApp = win32.Dispatch("Excel.Application")e
#Excelを開く
wb = xlApp.Workbooks.Open("E:/testFile.xlsx")
#Sheet取得
#番号またはSheet名
sheet = wb.Worksheets(1)
#Cell取得
cell = sheet.Cells(1,1)
#Cellに数字を入れる
cell.Value = 10
#関数を入れる
sheet.Range("A11").Formula = "=SUM(A1:A10)"
#シート名を変更
sheet.Name = "TEST NAME"
#セーブして閉じる
wb.Save()
wb.Close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment