Creating a budget overview from a SuperX export.
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
""" some helper functions """
|
|
|
|
|
|
|
|
import openpyxl
|
|
|
|
|
|
|
|
|
|
|
|
def excel_value_as_number(value):
|
|
|
|
if value is None:
|
|
|
|
return 0
|
|
|
|
if isinstance(value, str):
|
|
|
|
try:
|
|
|
|
return float(value)
|
|
|
|
except ValueError:
|
|
|
|
return 0
|
|
|
|
return value
|
|
|
|
|
|
|
|
|
|
|
|
def get_sheet_of_file(excel_file, sheet=None):
|
|
|
|
""" returns a sheet from an excel FileCache
|
|
|
|
|
|
|
|
if name is set to None, the function returns the first sheet
|
|
|
|
"""
|
|
|
|
workbook = openpyxl.open(excel_file)
|
|
|
|
if sheet is None:
|
|
|
|
all_sheets = workbook.sheetnames
|
|
|
|
sheet = all_sheets[0]
|
|
|
|
return workbook[sheet]
|
|
|
|
|
|
|
|
|
|
|
|
def is_empty_excel_value(value):
|
|
|
|
""" is the cell value considered empty """
|
|
|
|
if value is None:
|
|
|
|
return True
|
|
|
|
if isinstance(value, str) and value.strip() == "":
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
def strip_excel_value(value):
|
|
|
|
""" remove whitespace from an excel value if it is a string """
|
|
|
|
if isinstance(value, str):
|
|
|
|
return value.strip()
|
|
|
|
return value
|