Created
December 25, 2020 08:06
-
-
Save radityopw/d6e95d4626553d162c2687c27672b690 to your computer and use it in GitHub Desktop.
membaca, menulis excel dari python menggunaan win32 py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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