Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def combobox():
"""
This populates the ComboBox with the values from the database
"""
# Make a connection to the calling Excel file
wb = Book.caller()
# Place the database next to the Excel file
db_file = os.path.join(os.path.dirname(wb.fullname), 'chinook.sqlite')
# Database connection and creation of cursor
con = sqlite3.connect(db_file, detect_types=sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES)
cursor = con.cursor()
# Database Query
cursor.execute("SELECT PlaylistId, Name FROM Playlist")
# Write IDs and Names to hidden sheet
Range('Source', 'A1').table.clear_contents()
Range('Source', 'A1').value = cursor.fetchall()
# Format and fill the ComboBox to show Names (Text) and give back IDs (Values)
def _make_connections():
global wb, sht, directory
wb = xw.Book.caller()
sht = wb.sheets.active
directory = os.path.dirname(wb.fullname)
def playlist():
"""
Get the playlist content based on the ID from the Dropdown
"""
# Make a connection to the calling Excel file
wb = Book.caller()
# Place the database next to the Excel file
db_file = os.path.join(os.path.dirname(wb.fullname), 'chinook.sqlite')
# Database connection and creation of cursor
con = sqlite3.connect(db_file, detect_types=sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES)
cursor = con.cursor()
# Get PlaylistId from ComboBox
playlist_id = wb.xl_workbook.ActiveSheet.OLEObjects("ComboBox1").Object.Value
# Database query
cursor.execute(
"""
SELECT
t.Name AS Track, alb.Title AS Album, art.Name AS Artist, t.Composer
def get_harvest_time_entries():
wb = xw.Book.caller()
sheets = xw.sheets
time_entries_sheet = None
for sheet in sheets:
if sheet.name == 'Harvest Time Entries':
time_entries_sheet = sheet
if time_entries_sheet is not None:
time_entries_sheet.delete()
new_time_entries = sheets.add(name='Harvest Time Entries', after='Sheet1')
wb.app.screen_updating = False
wb.app.calculation = 'manual'
def main():
# Create a reference to the calling Excel Workbook
wb = xw.Book.caller()
# Get the constant from Excel
const = xw.Range('B1').value
# Get the figure and show it in Excel
fig = get_figure(const)
plot = xw.Plot(fig)
plot.show('MyStreamplot', sheet=1)
def make_employee_pivot_table():
# get the worksheet we are interested in (providing it exists)
wb = xw.Book.caller()
sheets = xw.sheets
working_sheet = None
for sheet in sheets:
if sheet.name == 'Employee Hours':
working_sheet = sheet
for col in range(1, working_sheet.used_range.columns.count + 1):
if working_sheet.cells(1, col).value == 'Project Code':
code_position = col
if working_sheet.cells(1, col).value == 'Last Name':
surname_position = col
if working_sheet.cells(1, col).value == 'total':
total_position = col
def employee_rate_and_total(sheet_range = 'Employee Hours', sheet_lookup = 'Employee Rates'):
# get the worksheet we are interested in (providing it exists)
wb = xw.Book.caller()
sheets = xw.sheets
working_sheet = None
for sheet in sheets:
if sheet.name == sheet_range:
working_sheet = sheet
if working_sheet is not None:
Lookup_cols = working_sheet.used_range.columns.count
Lookup_rows = working_sheet.used_range.rows.count + 1
rates_col = Lookup_cols + 1 #calculates the column number for the rates
total_col = Lookup_cols + 2 #calculates the row number for the rates
rows = working_sheet.used_range.rows.count #calculates the number of rows in "Sheet1"
code_position = 0
surname_position = 0
hours_position = 0
def refresh():
"""
Refreshes the tables in Excel given the input parameters.
"""
# Connect to the Workbook
wb = Book.caller()
# Read input
start_date = Range(sheet_dashboard, 'start_date').value
end_date = Range(sheet_dashboard, 'end_date').value
account_name = Range(sheet_dashboard, 'account').value
property_name = Range(sheet_dashboard, 'property').value
profile_name = Range(sheet_dashboard, 'view').value
max_results = Range(sheet_dashboard, 'max_rows').value
# Clear Content
Range(sheet_dashboard, 'behavior').clear_contents()
Range(sheet_dashboard, 'effective').clear_contents()
# Behavior table
behavior(start_date, end_date, account_name, property_name, profile_name, max_results)
def get_harvest_invoices():
wb = xw.Book.caller()
sheets = xw.sheets
invoice_sheet = None
for sheet in sheets:
if sheet.name == 'Harvest Invoices':
invoice_sheet = sheet
if invoice_sheet is not None:
invoice_sheet.delete()
new_invoices = sheets.add(name='Harvest Invoices', after='Sheet1')
wb.app.screen_updating = False
wb.app.calculation = 'manual'