Package: sheet2dict
sheet2dictA simple XLSX/CSV reader - to dictionary converterInstallingTo install the package from pip, first run:python3-mpipinstall--no-cache-dirsheet2dictRequired pip packages for sheet2doc: csv, openpyxlUsageThis library has 2 main features: reading a spreadsheet files and converting them to array of python dictionaries.- XLSXUsexlsx_to_dict()method  when converting form spreadsheets.Supported file formats for spreadsheets are: .xlsx,.xlsm,.xltx,.xltmSpreadsheets with multiple worksheets are supported. If no sheet is specified, the active sheet is selected. If there is only one sheet, it is considered active.# Import the libraryfromsheet2dictimportWorksheet# Create an objectws=Worksheet()# Convert active sheet (without specifying sheet name)ws.xlsx_to_dict(path='inventory.xlsx')# Convert the 'Main Warehouse' sheet of the 'inventory.xslx' spreadsheet file.ws.xlsx_to_dict(path='inventory.xlsx',select_sheet='Main Warehouse')# object.header returns first row with the data in a spreadsheetprint(ws.header)# object.sheet_items returns converted rows as dictionaries in the arrayprint(ws.sheet_items)You can parse data when worksheet is an object# Import the libraryfromsheet2dictimportWorksheet# Example: read spreadsheet as objectpath='inventory.xlsx'xlsx_file=open(path,'rb')xlsx_file=BytesIO(xlsx_file.read())# Parse spreadsheet from objectws=Worksheet()ws.xlsx_to_dict(path=xlsx_file)print(ws.header)- CSVUsecsv_to_dict()method  when converting form csv.CSV is a format with many variations, better handle encodings and delimiters on user side and not within module itself.# Import the libraryfromsheet2dictimportWorksheet# Create an objectws=Worksheet()# Read CSV filecsv_file=open('inventory.csv','r',encoding='utf-8-sig')# Convertws.csv_to_dict(csv_file=csv_file,delimiter=';')# object.header returns first row with the data in a spreadsheetprint(ws.header)# object.sheet_items returns converted rows as dictionaries in the arrayprint(ws.sheet_items)- Other functionsWorksheetobject.headerreturns first row with the data in a spreadsheetPython3.9.1[Clang12.0.0(clang-1200.0.32.28)]ondarwin>>>fromsheet2dictimportWorksheet>>>ws=Worksheet()>>>ws.xlsx_to_dict(path="inventory.xlsx")>>>ws.header{'country':'SK','city':'Bratislava','citizens':'400000','random_field':'cc'}Worksheetobject.sanitize_sheet_itemsremoves None or empty dictionary keys fromsheet_items>>>fromsheet2dictimportWorksheet>>>ws=Worksheet()>>>ws.xlsx_to_dict(path="inventory.xlsx")>>>ws.sheet_items[{'country':'CZ','city':'Prague','citizens':'600000',None:'22','random_field':'cc'},{'country':'UK','city':'London','citizens':'2000000',None:'33','random_field':'cc'}]>>>ws.sanitize_sheet_items[{'country':'CZ','city':'Prague','citizens':'600000','random_field':'cc'},{'country':'UK','city':'London','citizens':'2000000','random_field':'cc'}]Contributing and Code of ConductContributing to sheet2dictAs an open source project, sheet2dict welcomes contributions of many forms.Please read and follow ourContributing to sheet2dictContributors:Thanks to 白一百 (bái-yī-bǎi) for making sheet2dict work with multi-sheet Excel files.Code of ConductAs a contributor, you can help us keep the sheet2dict project open and inclusive.Please read and follow ourCode of Conduct