https://github.com/Pytlicek/sheet2dict Skip to content Sign up Sign up * Why GitHub? Features - + Mobile - + Actions - + Codespaces - + Packages - + Security - + Code review - + Project management - + Integrations - + GitHub Sponsors - + Customer stories- * Team * Enterprise * Explore + Explore GitHub - Learn and contribute + Topics - + Collections - + Trending - + Learning Lab - + Open source guides - Connect with others + The ReadME Project - + Events - + Community forum - + GitHub Education - + GitHub Stars program - * Marketplace * Pricing Plans - + Compare plans - + Contact Sales - + Education - [ ] [search-key] * # In this repository All GitHub | Jump to | * No suggested jump to results * # In this repository All GitHub | Jump to | * # In this user All GitHub | Jump to | * # In this repository All GitHub | Jump to | Sign in Sign up Sign up {{ message }} Pytlicek / sheet2dict * Notifications * Star 92 * Fork 2 Simple XLSX and CSV to dictionary converter pypi.org/project/sheet2dict/ MIT License 92 stars 2 forks Star Notifications * Code * Issues 0 * Pull requests 0 * Actions * Projects 0 * Security * Insights More * Code * Issues * Pull requests * Actions * Projects * Security * Insights main Switch branches/tags [ ] Branches Tags Nothing to show {{ refName }} default View all branches Nothing to show {{ refName }} default View all tags 1 branch 9 tags Go to file Code Clone HTTPS GitHub CLI [https://github.com/P] Use Git or checkout with SVN using the web URL. [gh repo clone Pytlic] Work fast with our official CLI. Learn more. * Open with GitHub Desktop * Download ZIP Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Go back Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Go back Launching Xcode If nothing happens, download Xcode and try again. Go back Launching Visual Studio If nothing happens, download the GitHub extension for Visual Studio and try again. Go back Latest commit @Pytlicek Pytlicek Update README.md ... 125b8b4 Apr 21, 2021 Update README.md 125b8b4 Git stats * 48 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time .github/workflows Update python-package.yml Mar 14, 2021 img Change the name of function "headers" to "header" as is in Pandas lib... Feb 10, 2021 sheet2dict Change the name of function "headers" to "header" as is in Pandas lib... Feb 10, 2021 tests Change the name of function "headers" to "header" as is in Pandas lib... Feb 10, 2021 .gitignore shee2dict initial commit Feb 7, 2021 CODE_OF_CONDUCT.md Create CODE_OF_CONDUCT.md Apr 4, 2021 CONTRIBUTING.md Update CONTRIBUTING.md Apr 4, 2021 LICENSE shee2dict initial commit Feb 7, 2021 README.md Update README.md Apr 21, 2021 pyproject.toml shee2dict initial commit Feb 7, 2021 requirements.txt Update requirements.txt Feb 7, 2021 setup.py Bump version to 0.0.10 Apr 4, 2021 upload.sh Update build process Feb 7, 2021 View code sheet2dict Installing Usage - XLSX - CSV - Other functions Contributing and Code of Conduct Contributing to sheet2dict Code of Conduct README.md Test Python package codecov Upload Python Package to PyPI PythonVersions Sourcery Black Snyk Downloads sheet2dict A simple XLSX/CSV reader - to dictionary converter Installing To install the package from pip, first run: python3 -m pip install --no-cache-dir sheet2dict Required pip packages for sheet2doc: csv, openpyxl [sheet2dict] Usage This library has 2 main features: reading a spreadsheet files and converting them to array of python dictionaries. - XLSX Use xlsx_to_dict() method when converting form spreadsheets. Supported file formats for spreadsheets are: .xlsx,.xlsm,.xltx,.xltm # Import the library from sheet2dict import Worksheet # Create an object ws = Worksheet() # Convert ws.xlsx_to_dict(path='inventory.xlsx') # object.header returns first row with the data in a spreadsheet print(ws.header) # object.sheet_items returns converted rows as dictionaries in the array print(ws.sheet_items) You can parse data when worksheet is an object # Import the library from sheet2dict import Worksheet # Example: read spreadsheet as object path = 'inventory.xlsx' xlsx_file = open(path, 'rb') xlsx_file = BytesIO(xlsx_file.read()) # Parse spreadsheet from object ws = Worksheet() ws.xlsx_to_dict(path=xlsx_file) print(ws.header) - CSV Use csv_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 library from sheet2dict import Worksheet # Create an object ws = Worksheet() # Read CSV file csv_file = open('inventory.csv', 'r', encoding='utf-8-sig') # Convert ws.csv_to_dict(csv_file=csv_file, delimiter=';') # object.header returns first row with the data in a spreadsheet print(ws.header) # object.sheet_items returns converted rows as dictionaries in the array print(ws.sheet_items) - Other functions Worksheet object.header returns first row with the data in a spreadsheet Python 3.9.1 [Clang 12.0.0 (clang-1200.0.32.28)] on darwin >>> from sheet2dict import Worksheet >>> ws = Worksheet() >>> ws.xlsx_to_dict(path="inventory.xlsx") >>> ws.header {'country': 'SK', 'city': 'Bratislava', 'citizens': '400000', 'random_field': 'cc'} Worksheet object.sanitize_sheet_items removes None or empty dictionary keys from sheet_items >>> from sheet2dict import Worksheet >>> 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 Conduct Contributing to sheet2dict As an open source project, sheet2dict welcomes contributions of many forms. Please read and follow our Contributing to sheet2dict Code of Conduct As a contributor, you can help us keep the sheet2dict project open and inclusive. Please read and follow our Code of Conduct About Simple XLSX and CSV to dictionary converter pypi.org/project/sheet2dict/ Topics csv xlsx python3 Resources Readme License MIT License Releases 9 0.0.10 Latest Apr 4, 2021 + 8 releases Languages * Python 97.5% * Shell 2.5% * (c) 2021 GitHub, Inc. * Terms * Privacy * Security * Status * Docs * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.