In this tutorial we are going to create a simple date picker tool for your Excel spreadsheet in Python.
This is the first tutorial I go into Excel and PyQt5 integration. Before go into the development, I want to touch on few things such as what are the advantages and disadvantages using PyQt5 Calender widget in Excel.
Buy Me a Coffee? Your support is much appreciated!
PayPal Me: https://www.paypal.me/jiejenn/5
Venmo: @Jie-Jenn
Full Script:
import sys, os
from PyQt5.QtWidgets import QApplication, QWidget, QCalendarWidget
import win32com.client as win32
xlApp = win32.Dispatch('Excel.Application')
xlApp.visible = True
class CalendarApp(QCalendarWidget):
def __init__(self):
super().__init__()
self.clicked.connect(self.insert_date)
def insert_date(self, date):
# return store_value(date)
try:
xlApp.Selection.value = date.toPyDate().strftime('%m-%d-%Y')
except Exception as e:
print(e)
app = QApplication(sys.argv)
cal = CalendarApp()
cal.show()
sys.exit(app.exec_())
Hey,
excellent and very helpful!
IS there any way to insert that date into cell i chose by the code? I mean to an existing workbook and to one cell i chose for example C5.
Thank you anyway! Greetings!