60 lines
2.0 KiB
Plaintext
60 lines
2.0 KiB
Plaintext
{
|
||
"cells": [
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"import openpyxl as xl #Импортирует библиотеку openpyxl, которая используется для работы с файлами Excel \n",
|
||
"import re #Импортирует модуль re, который предоставляет функции для работы с регулярными выражениями в Python.\n",
|
||
"path = r'stud.xlsx' #путь, к Excel файлу\n",
|
||
"wb = xl.load_workbook(filename=path, read_only=True)\n",
|
||
"ws = wb['Название листа'] #Название листа книги"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"for row in ws.rows:\n",
|
||
" for cell in row:\n",
|
||
" if cell.value and isinstance(cell.value, str): # Проверка на наличие значения и его тип\n",
|
||
" if re.match(r'Фамилия*', cell.value): # Искомое значение\n",
|
||
" print(f\"Искомый студент: {cell.value}\")\n",
|
||
" next_cell = ws.cell(row=cell.row, column=cell.column + 1) # Ячейка следующей колонки\n",
|
||
" print(f\"Количество опозданий: {next_cell.value}\")"
|
||
]
|
||
}
|
||
],
|
||
"metadata": {
|
||
"kernelspec": {
|
||
"display_name": "Python 3.9.6 64-bit",
|
||
"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.9.6"
|
||
},
|
||
"orig_nbformat": 4,
|
||
"vscode": {
|
||
"interpreter": {
|
||
"hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
|
||
}
|
||
}
|
||
},
|
||
"nbformat": 4,
|
||
"nbformat_minor": 2
|
||
}
|