{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Чтение Excel файлов" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from openpyxl import load_workbook" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "wb = load_workbook(\"data/test.xlsx\")\n", "# https://github.com/dm-fedorov/python_basic/blob/master/data/test.xlsx" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "result = []" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "ws = wb.worksheets[0]" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "for row in ws.iter_rows():\n", " result.append([cell.value for cell in row])" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[['Note', 'Code', 'Year'], [1.0, 34.0, 2020.0], [2.0, 345.0, 2020.0], [3.0, 234.0, 2020.0], [4.0, 234.0, 2020.0], [5.0, 6.0, 2020.0], [6.0, 5.0, 2020.0], [7.0, 34.0, 2020.0], [8.0, 3.0, 2020.0], [9.0, 45.0, 2020.0]]\n" ] } ], "source": [ "print(result)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.10" } }, "nbformat": 4, "nbformat_minor": 4 }