Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@radityopw
Created December 25, 2020 08:06
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 radityopw/d6e95d4626553d162c2687c27672b690 to your computer and use it in GitHub Desktop.
Save radityopw/d6e95d4626553d162c2687c27672b690 to your computer and use it in GitHub Desktop.
membaca, menulis excel dari python menggunaan win32 py
# install library
pip install pywin32
# import komponen
import win32com.client
# untuk membuka excel
xl = win32com.client.Dispatch('Excel.Application')
# untuk memperlihatkan excel nya
xl.Visible = True
# untuk keluar dari aplikasi
xl.Quit()
# Save excel doc
wb.Save()
# Save As current excel doc
#wb.SaveAs(file)
# untuk membuka workbook
wb = xl.Workbooks.Open(file)
# jumlah sheets
wb.worksheets.count
# get list worksheets name
for ws in wb.worksheets :
print(ws.name)
# selecting worksheet
ws = wb.worksheets(NAME)
# ambil value
# baris, kolom dimulai dari 1
ws.cells(baris,kolom).value
# isi cells
ws.cells(baris,kolom).value = "value"
# seperti value tapi formula
ws.cells(baris,kolom).formula
ws.cells(baris,kolom).formula = "=A6"
# jumlah baris
ws.rows.count
# jumlah kolom
ws.columns.count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment