📋 المحتوى المنظم
📖 محتوى تعليمي مفصّل
سمة الصف الأقصى (max_row attribute) وسمة العمود الأقصى (max_column attribute)
نوع: محتوى تعليمي
سمة الصف الأقصى (max_row attribute) وسمة العمود الأقصى (max_column attribute)
نوع: محتوى تعليمي
عند العمل باستخدام ملف إكسل، فمن الجيد معرفة عدد الصفوف والأعمدة الموجودة في الورقة. للقيام بذلك، يمكنك استخدام سمة الصف الأقصى (max_row) وسمة العمود الأقصى (max_column) في ورقة العمل.
الوصول إلى الخلايا
نوع: محتوى تعليمي
الوصول إلى الخلايا
نوع: محتوى تعليمي
تحتوي كل خلية في ورقة عمل إكسل على خاصيتين رئيستين، هما موقعها في الملف وقيمته. غالبًا ما ستحتاج إلى الوصول إلى قيمة الخلية من أجل طباعتها على الشاشة، أو تغييرها، أو استخدامها لإجراء عمليات حسابية أخرى مثل العثور على مبلغ وما إلى ذلك.
نوع: NON_EDUCATIONAL
وزارة التعليم Ministry of Education 2025 - 1447
🔍 عناصر مرئية
Python Code: Determining Max Row and Column
A Python code snippet demonstrating the use of the `openpyxl` library to load an Excel workbook named 'nutrition.xlsx', access the sheet named 'arabic', and then print the maximum row and column numbers found in that sheet using `sheet_obj.max_row` and `sheet_obj.max_column` attributes. The code is:
```python
import openpyxl
path = "nutrition.xlsx"
wb = openpyxl.load_workbook(path)
sheet_obj = wb['arabic']
row = sheet_obj.max_row
column = sheet_obj.max_column
print("إجمالي السطور:", row)
print("إجمالي الأعمدة:", column)
```
A pink highlighted box containing the definition of 'Attributes' in programming.
A light blue highlighted box explaining the purpose of assigning the 'arabic' sheet to the `sheet_obj` variable.
A light blue highlighted box showing the output of the first Python code block, indicating the total number of rows and columns found.
Python Code: Accessing Individual Cells and Ranges
A Python code snippet using `openpyxl` to load an Excel workbook, access the 'arabic' sheet, then access a specific cell 'A1', print its type and value, and define a cell range from 'B1' to 'B5'. The code includes Arabic comments: '# الوصول إلى الخلايا من ورقة العمل كمفاتيح لدفتر العمل' and '# لعرض نوع الخلية'.
```python
import openpyxl
path = "nutrition.xlsx"
wb = openpyxl.load_workbook(path)
sheet_obj = wb['arabic'] # الوصول إلى الخلايا من ورقة العمل كمفاتيح لدفتر العمل
cell = sheet_obj["A1"] # لعرض نوع الخلية
print(type(cell))
cell_range = sheet_obj["B1"] : "B5"]
print(cell)
```
A light blue highlighted box explaining the purpose of assigning cell 'A1' to the `cell` variable.
A light blue highlighted box showing the output of the `print(type(cell))` and `print(cell)` lines from the second Python code block, indicating the class type of the cell object and its sheet and location.
A light blue highlighted box explaining the meaning of the cell range syntax 'B1':'B5'.
A light blue highlighted box interpreting the output '<Cell "arabic".A1>' as the sheet name and cell location.
📄 النص الكامل للصفحة
--- SECTION: سمة الصف الأقصى (max_row attribute) وسمة العمود الأقصى (max_column attribute) ---
سمة الصف الأقصى (max_row attribute) وسمة العمود الأقصى (max_column attribute)
عند العمل باستخدام ملف إكسل، فمن الجيد معرفة عدد الصفوف والأعمدة الموجودة في الورقة. للقيام بذلك، يمكنك استخدام سمة الصف الأقصى (max_row) وسمة العمود الأقصى (max_column) في ورقة العمل.
--- SECTION: الوصول إلى الخلايا ---
الوصول إلى الخلايا
تحتوي كل خلية في ورقة عمل إكسل على خاصيتين رئيستين، هما موقعها في الملف وقيمته. غالبًا ما ستحتاج إلى الوصول إلى قيمة الخلية من أجل طباعتها على الشاشة، أو تغييرها، أو استخدامها لإجراء عمليات حسابية أخرى مثل العثور على مبلغ وما إلى ذلك.
وزارة التعليم Ministry of Education 2025 - 1447
--- VISUAL CONTEXT ---
**FIGURE**: Python Code: Determining Max Row and Column
Description: A Python code snippet demonstrating the use of the `openpyxl` library to load an Excel workbook named 'nutrition.xlsx', access the sheet named 'arabic', and then print the maximum row and column numbers found in that sheet using `sheet_obj.max_row` and `sheet_obj.max_column` attributes. The code is:
```python
import openpyxl
path = "nutrition.xlsx"
wb = openpyxl.load_workbook(path)
sheet_obj = wb['arabic']
row = sheet_obj.max_row
column = sheet_obj.max_column
print("إجمالي السطور:", row)
print("إجمالي الأعمدة:", column)
```
Context: This code illustrates how to programmatically inspect the dimensions of a spreadsheet, which is fundamental for data processing and automation.
**HIGHLIGHT_BOX**: Untitled
Description: A pink highlighted box containing the definition of 'Attributes' in programming.
Key Values: السمات (Attributes) هي بعض الخصائص المضمنة لنوع خاص من المتغيرات، وتسمى الكائنات.
Context: Provides a key programming definition relevant to understanding object-oriented concepts used in libraries like `openpyxl`.
**HIGHLIGHT_BOX**: Untitled
Description: A light blue highlighted box explaining the purpose of assigning the 'arabic' sheet to the `sheet_obj` variable.
Key Values: يحمل هذا الأمر الورقة المسماة "arabic" في متغير .sheet_obj
Context: Clarifies a specific line of code, explaining how a particular worksheet is referenced in the program.
**HIGHLIGHT_BOX**: Untitled
Description: A light blue highlighted box showing the output of the first Python code block, indicating the total number of rows and columns found.
Key Values: إجمالي الصفوف: 12, إجمالي الأعمدة: 12
Context: Presents the result of executing the code, confirming the dimensions of the 'arabic' sheet.
**FIGURE**: Python Code: Accessing Individual Cells and Ranges
Description: A Python code snippet using `openpyxl` to load an Excel workbook, access the 'arabic' sheet, then access a specific cell 'A1', print its type and value, and define a cell range from 'B1' to 'B5'. The code includes Arabic comments: '# الوصول إلى الخلايا من ورقة العمل كمفاتيح لدفتر العمل' and '# لعرض نوع الخلية'.
```python
import openpyxl
path = "nutrition.xlsx"
wb = openpyxl.load_workbook(path)
sheet_obj = wb['arabic'] # الوصول إلى الخلايا من ورقة العمل كمفاتيح لدفتر العمل
cell = sheet_obj["A1"] # لعرض نوع الخلية
print(type(cell))
cell_range = sheet_obj["B1"] : "B5"]
print(cell)
```
Context: This code demonstrates how to programmatically interact with specific cells and define ranges within a spreadsheet, which is crucial for reading and manipulating data.
**HIGHLIGHT_BOX**: Untitled
Description: A light blue highlighted box explaining the purpose of assigning cell 'A1' to the `cell` variable.
Key Values: يحمل هذا الأمر الخلية "A1" في متغير .sheet_obj
Context: Clarifies a specific line of code, explaining how an individual cell is referenced in the program.
**HIGHLIGHT_BOX**: Untitled
Description: A light blue highlighted box showing the output of the `print(type(cell))` and `print(cell)` lines from the second Python code block, indicating the class type of the cell object and its sheet and location.
Key Values: <class 'openpyxl.cell.cell.Cell'>, <Cell "arabic".A1>
Context: Presents the result of executing the code, showing the data type and specific reference of the accessed cell.
**HIGHLIGHT_BOX**: Untitled
Description: A light blue highlighted box explaining the meaning of the cell range syntax 'B1':'B5'.
Key Values: هذا يعني الانتقال من الخلية "B1" إلى الخلية "B5"
Context: Clarifies the syntax for defining a range of cells in `openpyxl`.
**HIGHLIGHT_BOX**: Untitled
Description: A light blue highlighted box interpreting the output '<Cell "arabic".A1>' as the sheet name and cell location.
Key Values: اسم الورقة وموقع الخلية
Context: Explains how to interpret the string representation of a cell object, showing its sheet and address.
🎴 بطاقات تعليمية للمراجعة
عدد البطاقات: 5 بطاقة لهذه الصفحة
في مكتبة openpyxl، ما الغرض من استخدام السمة `max_row`؟
- أ) لحساب مجموع القيم في جميع الصفوف.
- ب) للعثور على عدد الصفوف الموجودة في ورقة العمل.
- ج) لتحديد اسم الصف الأخير في الورقة.
- د) لطباعة محتويات الصف الأخير على الشاشة.
الإجابة الصحيحة: b
الإجابة: للعثور على عدد الصفوف الموجودة في ورقة العمل.
الشرح: 1. السمة `max_row` هي خاصية مضمنة لكائن ورقة العمل في مكتبة openpyxl.
2. تُستخدم لاسترداد رقم الصف الأخير الذي يحتوي على بيانات في الورقة.
3. هذا مفيد لمعرفة نطاق البيانات ومعالجتها برمجياً دون الحاجة إلى عد يدوي.
تلميح: تتعلق هذه السمة بحجم البيانات في جدول البيانات.
التصنيف: مفهوم جوهري | المستوى: سهل
في سياق برمجة معالجة ملفات Excel باستخدام openpyxl، ما هي السمات (Attributes)؟
- أ) هي الأوامر البرمجية المستخدمة لتحميل ملف إكسل.
- ب) هي بعض الخصائص المضمنة لنوع خاص من المتغيرات، وتسمى الكائنات.
- ج) هي القيم المخزنة داخل خلايا جدول البيانات.
- د) هي أسماء المتغيرات التي نعرفها في البرنامج.
الإجابة الصحيحة: b
الإجابة: هي بعض الخصائص المضمنة لنوع خاص من المتغيرات، وتسمى الكائنات.
الشرح: 1. في البرمجة، وخاصة البرمجة الكائنية التوجه (OOP)، الكائنات لها خصائص.
2. السمات (Attributes) هي هذه الخصائص المضمنة أو المخزنة داخل الكائن.
3. في مكتبة openpyxl، `max_row` و `max_column` هما مثالان على سمات كائن ورقة العمل (Worksheet).
تلميح: تتعلق بمفاهيم البرمجة الكائنية (OOP).
التصنيف: تعريف | المستوى: متوسط
في الكود البرمجي `sheet_obj = wb['arabic']`، ما الذي يفعله هذا السطر؟
- أ) ينشئ ورقة عمل جديدة باسم 'arabic'.
- ب) يحذف الورقة المسماة 'arabic' من المصنف.
- ج) يحمل الورقة المسماة 'arabic' في متغير sheet_obj.
- د) يطبع محتويات الورقة 'arabic' على الشاشة.
الإجابة الصحيحة: c
الإجابة: يحمل الورقة المسماة 'arabic' في متغير sheet_obj.
الشرح: 1. `wb` هو متغير يمثل كائن المصنف (Workbook) الذي تم تحميله.
2. `wb['arabic']` هو طريقة للوصول إلى ورقة عمل محددة داخل هذا المصنف باسمها.
3. يتم تعيين المرجع إلى هذه الورقة للمتغير `sheet_obj` لاستخدامه لاحقاً للوصول إلى خلاياها وسماتها.
تلميح: يربط المتغير بورقة عمل محددة داخل المصنف.
التصنيف: مفهوم جوهري | المستوى: سهل
عند تنفيذ الأمر `cell = sheet_obj['A1']` ثم `print(type(cell))`، ما هو نوع المخرجات المتوقع؟
- أ) <class 'int'>
- ب) <class 'str'>
- ج) <class 'openpyxl.cell.cell.Cell'>
- د) <class 'worksheet'>
الإجابة الصحيحة: c
الإجابة: <class 'openpyxl.cell.cell.Cell'>
الشرح: 1. `sheet_obj['A1']` يُرجع كائنًا يمثل الخلية A1 في ورقة العمل.
2. في مكتبة openpyxl، يتم تمثيل الخلايا بواسطة فئة (class) تسمى `Cell`.
3. الدالة `type()` تُرجع نوع الكائن، والذي سيكون الفئة التي ينتمي إليها، أي `openpyxl.cell.cell.Cell`.
تلميح: يخبرنا نوع البيانات المخزن في المتغير `cell`.
التصنيف: سؤال اختبار | المستوى: متوسط
ما معنى التعبير `sheet_obj['B1':'B5']` في مكتبة openpyxl؟
- أ) يحذف الخلايا من B1 إلى B5.
- ب) يطبع قيمة الخلية B1 فقط.
- ج) يحسب متوسط القيم في الخلايا من B1 إلى B5.
- د) هذا يعني الانتقال من الخلية 'B1' إلى الخلية 'B5' (يشير إلى نطاق من الخلايا).
الإجابة الصحيحة: d
الإجابة: هذا يعني الانتقال من الخلية 'B1' إلى الخلية 'B5' (يشير إلى نطاق من الخلايا).
الشرح: 1. في مكتبة openpyxl، يمكن تحديد نطاق من الخلايا باستخدام النقطتين الرأسيتين `:`.
2. `'B1':'B5'` يحدد جميع الخلايا في العمود B من الصف 1 إلى الصف 5.
3. هذا النطاق يمكن استخدامه لقراءة أو كتابة قيم في مجموعة خلايا دفعة واحدة.
تلميح: يحدد مجموعة من الخلايا، وليس خلية واحدة.
التصنيف: مفهوم جوهري | المستوى: سهل