إدارة الضوابط
مقدمة
يمكن للمطورين إضافة أشكال رسومية مختلفة مثل مربعات النص، مربعات الاختيار، أزرار الراديو، مربعات الاختيار، التسميات، الأزرار، الخطوط، المستطيلات، الأقواس، الدوائر، المفاتيح الدوارة، أشرطة التمرير، صناديق المجموعة، وغيرها. توفر Aspose.Cells لـ بايثون via .NET مساحة أسماء Aspose.Cells.Drawing التي تحتوي على جميع الأشكال الرسومية. ومع ذلك، هناك عدد قليل من الأشكال غير المدعومة بعد. قم بإنشاء هذه الأشكال في جدول تصميم باستخدام Microsoft Excel ثم استورد جدول التصميم إلى Aspose.Cells. تتيح لك Aspose.Cells لـ بايثون via .NET تحميل هذه الأشكال من جدول التصميم وكتابتها إلى ملف تم إنشاؤه.
إضافة مربع نص إلى ورقة العمل
إحدى الطرق لإبراز المعلومات المهمة في تقرير هو استخدام مربع نص. على سبيل المثال، إضافة نص لتسليط الضوء على اسم الشركة أو للإشارة إلى المنطقة الجغرافية ذات أعلى مبيعات، وغيرها. توفر Aspose.Cells لـ بايثون via .NET الفئة TextBoxCollection، المستخدمة لإضافة مربع نص جديد إلى المجموعة. هناك فئة أخرى، TextBox، تمثل مربع النص المستخدم لتعريف جميع أنواع الإعدادات. تحتوي على بعض الأعضاء المهمة:
- الخاصية text_frame تُرجع كائن MsoTextFrame يُستخدم لضبط محتويات صندوق النص.
- الخاصية placement تُحدد نوع التوضع.
- الخاصية font تُحدد سمات الخط.
- الطريقة add_hyperlink تضيف ارتباطًا تشعبيًا لصندوق النص.
- الخاصية fill_format ترجع كائن MsoFillFormat يُستخدم لتعيين تنسيق التعبئة لصندوق النص.
- تُعيد الخاصية line_format كائن MsoLineFormat المستخدم عادة لتنسيق ووزن خط مربع النص.
- الخاصية text تحدد النص الذي يُدخل في صندوق النص.
المثال التالي ينشئ مربعي نص في الورقة العمل الأولى من الدفتر. المربع النص الأول مؤثث جيدًا بإعدادات تنسيق مختلفة. الثاني بسيط.
from aspose.cells import Workbook | |
from aspose.cells.drawing import MsoLineDashStyle, PlacementType | |
from aspose.pydrawing import Color | |
from os import os, path | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Create directory if it is not already present. | |
IsExists = path.isdir(dataDir) | |
if notIsExists: | |
os.makedirs(dataDir) | |
# Instantiate a new Workbook. | |
workbook = Workbook() | |
# Get the first worksheet in the book. | |
worksheet = workbook.worksheets[0] | |
# Add a new textbox to the collection. | |
textboxIndex = worksheet.text_boxes.add(2, 1, 160, 200) | |
# Get the textbox object. | |
textbox0 = worksheet.text_boxes[textboxIndex] | |
# Fill the text. | |
textbox0.text = "ASPOSE______The .NET & JAVA Component Publisher!" | |
# Get the textbox text frame. | |
# MsoTextFrame textframe0 = textbox0.TextFrame; | |
# Set the textbox to adjust it according to its contents. | |
# textframe0.AutoSize = true; | |
# Set the placement. | |
textbox0.placement = PlacementType.FREE_FLOATING | |
# Set the font color. | |
textbox0.font.color = Color.blue | |
# Set the font to bold. | |
textbox0.font.is_bold = True | |
# Set the font size. | |
textbox0.font.size = 14 | |
# Set font attribute to italic. | |
textbox0.font.is_italic = True | |
# Add a hyperlink to the textbox. | |
textbox0.add_hyperlink("http:// Www.aspose.com/") | |
# Get the filformat of the textbox. | |
fillformat = textbox0.fill | |
# Get the lineformat type of the textbox. | |
lineformat = textbox0.line | |
# Set the line weight. | |
lineformat.weight = 6.0 | |
# Set the dash style to squaredot. | |
lineformat.dash_style = MsoLineDashStyle.SQUARE_DOT | |
# Add another textbox. | |
textboxIndex = worksheet.text_boxes.add(15, 4, 85, 120) | |
# Get the second textbox. | |
textbox1 = worksheet.text_boxes[textboxIndex] | |
# Input some text to it. | |
textbox1.text = "This is another simple text box" | |
# Set the placement type as the textbox will move and | |
# Resize with cells. | |
textbox1.placement = PlacementType.MOVE_AND_SIZE | |
# Save the excel file. | |
workbook.save(dataDir + "book1.out.xls") |
التحكم في صندوقات النص في جداول البيانات المصممة
يمكنك أيضًا باستخدام Aspose.Cells لـ بايثون via .NET الوصول إلى مربعات النص في أوراق العمل المصممة والتعديل عليها. استخدم الخاصية Worksheet.TextBoxes للحصول على مجموعة مربعات النص في الورقة.
يستخدم المثال التالي ملف Microsoft Excel الذي أنشأناه في المثال أعلاه. يحصل على سلاسل نصيّة لصندوقي النص ويغير نص الصندوق الثاني لحفظ الملف.
from aspose.cells import Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Instantiate a new Workbook. | |
# Open the existing excel file. | |
workbook = Workbook(dataDir + "book1.xls") | |
# Get the first worksheet in the book. | |
worksheet = workbook.worksheets[0] | |
# Get the first textbox object. | |
textbox0 = worksheet.text_boxes[0] | |
# Obtain the text in the first textbox. | |
text0 = textbox0.text | |
# Get the second textbox object. | |
textbox1 = worksheet.text_boxes[1] | |
# Obtain the text in the second textbox. | |
text1 = textbox1.text | |
# Change the text of the second textbox. | |
textbox1.text = "This is an alternative text" | |
# Save the excel file. | |
workbook.save(dataDir + "output.out.xls") |
إضافة عنصر تحكم خانة اختيار إلى ورقة العمل
مربعات الاختيار مفيدة إذا كنت تريد توفير طريقة لمستخدم لاختيار بين خيارين، مثل صواب أو خطأ؛ نعم أم لا. تتيح لك Aspose.Cells لـ بايثون via .NET استخدام مربعات الاختيار في أوراق العمل. على سبيل المثال، ربما تكون قد أعددت ورقة توقعات مالية والتي يمكنك فيها إما حساب عملية استحواذ معينة أو عدمها. في هذه الحالة، قد ترغب في وضع مربع اختيار في أعلى ورقة العمل. يمكنك ربط حالة مربع الاختيار بخلية أخرى، بحيث إذا تم تحديد مربع الاختيار، تكون قيمة الخلية True؛ وإذا لم يتم تحديده، تكون قيمة الخلية False.
استخدام Microsoft Excel
لوضع تحكم مربع الاختيار في ورقة العمل الخاصة بك، اتبع هذه الخطوات:
- تأكد من عرض شريط الأدوات النماذج.
- انقر على أداة مربع اختيار في شريط الأدوات النماذج.
- في منطقة ورقة العمل الخاصة بك، انقر واسحب لتحديد المستطيل الذي سيحتوي على مربع الاختيار والتسمية بجانب مربع الاختيار.
- بمجرد وضع مربع الاختيار، قم بتحريك مؤشر الماوس إلى منطقة التسمية وقم بتغيير التسمية.
- في حقل رابط الخلية، حدد عنوان الخلية التي يجب ربط مربع الاختيار بها.
- انقر فوق موافق.
باستخدام Aspose.Cells لبايثون via .NET
يقدم Aspose.Cells for Python via .NET فئة CheckBoxCollection، التي تُستخدم لإضافة مربع اختيار جديد إلى المجموعة. هناك فئة أخرى، Aspose.Cells.Drawing.CheckBox، والتي تمثل مربع اختيار. لديها بعض الأعضاء المهمة:
- تحدد خاصية linked_cell خلية مرتبطة بخانة الاختيار.
- تحدد خاصية text السلسلة النصية المرتبطة بخانة الاختيار. إنها تسمية خانة الاختيار.
- تحدد خاصية value ما إذا كانت خانة الاختيار محددة أم لا.
يوضح المثال التالي كيفية إضافة خانة اختيار إلى ورقة العمل.
from aspose.cells import Workbook | |
from os import os, path | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Create directory if it is not already present. | |
IsExists = path.isdir(dataDir) | |
if notIsExists: | |
os.makedirs(dataDir) | |
# Instantiate a new Workbook. | |
excelbook = Workbook() | |
# Add a checkbox to the first worksheet in the workbook. | |
index = excelbook.worksheets[0].check_boxes.add(5, 5, 100, 120) | |
# Get the checkbox object. | |
checkbox = excelbook.worksheets[0].check_boxes[index] | |
# Set its text string. | |
checkbox.text = "Click it!" | |
# Put a value into B1 cell. | |
excelbook.worksheets[0].cells.get("B1").put_value("LnkCell") | |
# Set B1 cell as a linked cell for the checkbox. | |
checkbox.linked_cell = "B1" | |
# Check the checkbox by default. | |
checkbox.value = True | |
# Save the excel file. | |
excelbook.save(dataDir + "book1.out.xls") |
إضافة عنصر تحكم زر الراديو إلى ورقة العمل
زر الراديو أو زر الخيار هو عنصر تحكم مكون من صندوق مستدير. يقوم المستخدم باتخاذ قراره عن طريق تحديد مربع المستدير. يتم عادةً ، إذا لم يكن دائمًا ، خيار زر الراديو مصحوبًا بآخرين. يظهر زر الراديو ويتصرف كمجموعة. يقرر المستخدم أي زر صالح عن طريق تحديد واحد فقط منها. عندما ينقر المستخدم على زر واحد ، يتم ملؤه. عند تحديد زر واحد في المجموعة ، تكون أزرار نفس المجموعة فارغة.
استخدام Microsoft Excel
لوضع عنصر تحكم زر الراديو في ورقتك العمل ، اتبع هذه الخطوات:
- تأكد من عرض شريط الأدوات النماذج.
- انقر على أداة Button الخيار.
- في ورقة العمل ، انقر واسحب لتحديد المستطيل الذي سيحتوي على زر الخيار والتسمية بجانب زر الخيار.
- بمجرد وضع زر الراديو في ورقة العمل ، قم بتحريك مؤشر الماوس إلى منطقة التسمية وقم بتغيير التسمية.
- في حقل رابط الخلية ، حدد عنوان الخلية التي يجب أن يكون مرتبطًا بها زر الراديو هذا.
- انقر على موافق.
باستخدام Aspose.Cells لبايثون via .NET
توفر الفئة Aspose.Cells.Drawing.ShapeCollection طريقة تسمى add_radio_button، والتي تُستخدم لإضافة عنصر تحكم زر الراديو إلى ورقة عمل. تُرجع الطريقة كائنًا Aspose.Cells.Drawing.RadioButton. تمثل الفئة Aspose.Cells.Drawing.RadioButton زر اختيار. لها بعض الأعضاء الهامة:
- يُحدد خاصية linked_cell الخلية المرتبطة بزر الراديو.
- تُحدد خاصية text سلسلة النص المرتبطة بزر الراديو. إنها علامة زر الراديو.
- تُحدد خاصية is_checked ما إذا كان زر الراديو محددًا أم لا.
- تُحدد خاصية fill_format تنسيق التعبئة لزر الراديو.
- تُحدد خاصية line_format أنماط تنسيق الخط لزر الخيار.
المثال التالي يوضح كيفية إضافة أزرار الراديو إلى ورقة العمل. يضيف المثال ثلاثة أزرار راديو تمثل مجموعات عمرية.
إضافة عنصر تحكم مربع القائمة المنسدلة إلى ورقة العمل
لتسهيل إدخال البيانات، أو لتقييد الإدخالات إلى بعض العناصر التي تعرفها، يمكنك إنشاء مربع قائمة منسدلة، أو قائمة منسدلة للإدخالات الصحيحة التي تتم تجميعها من خلايا في مكان آخر على ورقة العمل. عند إنشاء قائمة منسدلة لخلية، تظهر سهم بجانب تلك الخلية. لإدخال معلومات في تلك الخلية، انقر على السهم، ثم انقر على الإدخال الذي تريده.
استخدام Microsoft Excel
لوضع عنصر تحكم مربع الجمع في ورقة العمل الخاصة بك، اتبع هذه الخطوات:
- تأكد من عرض شريط الأدوات النماذج.
- انقر على أداة مربع الجمع.
- في منطقة ورقة العمل الخاصة بك، انقر واسحب لتعريف المستطيل الذي سيحمل مربع الجمع.
- بمجرد أن يتم وضع مربع الجمع في ورقة العمل، انقر بزر الماوس الأيمن على عنصر التحكم ثم انقر على تنسيق التحكم وحدد نطاق الإدخال.
- في حقل ارتباط الخلية، حدد عنوان الخلية التي يجب ربطها بهذا مربع الجمع.
- انقر فوق موافق.
باستخدام Aspose.Cells لبايثون via .NET
توفر فئة Aspose.Cells.Drawing.ShapeCollection طريقة تحمل اسم add_combo_box، والتي تُستخدم لإضافة عنصر تحكم مربع الجمع إلى ورقة العمل. تُعيد الطريقة كائن Aspose.Cells.Drawing.ComboBox. الفئة Aspose.Cells.Drawing.ComboBox تمثل مربع جمع. لديها بعض الأعضاء المهمة:
- يحدد الخاصية linked_cell خلية مرتبطة بمربع الجمع.
- تحدد الخاصية input_range نطاق ورقة العمل للخلايا المستخدمة لملء مربع الجمع.
- تحدد الخاصية drop_down_lines عدد خطوط القائمة المعروضة في الجزء المنسدل لمربع الجمع.
- تُشير الخاصية shadow ما إذا كان مربع الجمع له تظليل ثلاثي الأبعاد.
المثال التالي يوضح كيفية إضافة مربع الجمع إلى ورقة العمل.
from aspose.cells import Workbook | |
from os import os, path | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Create directory if it is not already present. | |
IsExists = path.isdir(dataDir) | |
if notIsExists: | |
os.makedirs(dataDir) | |
# Create a new Workbook. | |
workbook = Workbook() | |
# Get the first worksheet. | |
sheet = workbook.worksheets[0] | |
# Get the worksheet cells collection. | |
cells = sheet.cells | |
# Input a value. | |
cells.get("B3").put_value("Employee:") | |
# Set it bold. | |
cells.get("B3").get_style().font.is_bold = True | |
# Input some values that denote the input range | |
# For the combo box. | |
cells.get("A2").put_value("Emp001") | |
cells.get("A3").put_value("Emp002") | |
cells.get("A4").put_value("Emp003") | |
cells.get("A5").put_value("Emp004") | |
cells.get("A6").put_value("Emp005") | |
cells.get("A7").put_value("Emp006") | |
# Add a new combo box. | |
comboBox = sheet.shapes.add_combo_box(2, 0, 2, 0, 22, 100) |
إضافة عنصر تحكم تسمية إلى ورقة العمل
التسميات هي وسيلة لإعطاء المستخدمين معلومات عن محتويات جدول البيانات. يتيح لك Aspose.Cells for Python via .NET إضافة وتعديل التسميات في ورقة العمل. توفر فئة ShapeCollection طريقة تسمى add_label، تُستخدم لإضافة عنصر تحكم تصنيف إلى ورقة العمل. ترجع الطريقة كائن Label. تمثل فئة Label تصنيفًا في ورقة العمل. لديها بعض الأعضاء المهمة:
- تحدد الطريقة text سلسلة تسمية التسمية.
- تحدد الطريقة placement PlacementType، الطريقة التي يتم بها تثبيت التسمية على الخلايا في ورقة العمل.
المثال التالي يوضح كيفية إضافة تسمية إلى ورقة العمل.
from aspose.cells import Workbook | |
from aspose.cells.drawing import PlacementType | |
from os import os, path | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Create directory if it is not already present. | |
IsExists = path.isdir(dataDir) | |
if notIsExists: | |
os.makedirs(dataDir) | |
# Create a new Workbook. | |
workbook = Workbook() | |
# Get the first worksheet in the workbook. | |
sheet = workbook.worksheets[0] | |
# Add a new label to the worksheet. | |
label = sheet.shapes.add_label(2, 0, 2, 0, 60, 120) | |
# Set the caption of the label. | |
label.text = "This is a Label" | |
# Set the Placement Type, the way the | |
# Label is attached to the cells. | |
label.placement = PlacementType.FREE_FLOATING | |
# Saves the file. | |
workbook.save(dataDir + "book1.out.xls") |
إضافة عنصر تحكم مربع القائمة إلى ورقة العمل
ينشئ عنصر تحكم مربع القائمة عنصر تحكم يسمح باختيار عنصر واحد أو عدة عناصر.
استخدام Microsoft Excel
لوضع عنصر تحكم مربع القائمة في ورقة العمل:
- تأكد من عرض شريط الأدوات النماذج.
- انقر على أداة مربع القائمة.
- في منطقة ورقة العمل الخاصة بك، انقر واسحب لتعريف المستطيل الذي سيحتوي على مربع القائمة.
- بمجرد وضع مربع القائمة في ورقة العمل، انقر بزر الماوس الأيمن على العنصر التحكم للنقر فوق تنسيق العنصر التحكم وتحديد نطاق الإدخال.
- في حقل رابط الخلية، حدد عنوان الخلية التي يجب أن يكون مربع القائمة مرتبطًا بها وتعيين نوع الاختيار (فردي، متعدد، توسيع) السمة
- انقر على موافق.
باستخدام Aspose.Cells لبايثون via .NET
توفر فئة ShapeCollection طريقة تُسمى add_list_box، والتي تُستخدم لإضافة عنصر تحكم مربع قائمة إلى ورقة العمل. تعيد الطريقة كائنًا Aspose.Cells.Drawing.ListBox. تُمثل الفئة ListBox مربع قائمة. لها بعض الأعضاء الهامة:
- تحدد الطريقة linked_cell خلية مقترنة بمربع القائمة.
- تحدد الطريقة input_range نطاق ورقة العمل للخلايا المستخدمة لملء مربع القائمة.
- تحدد الطريقة selection_type وضع تحديد مربع القائمة.
- تُشير الطريقة shadow ما إذا كان لمربع القائمة تظليل ثلاثي الأبعاد.
يوضح المثال التالي كيفية إضافة مربع قائمة إلى ورقة العمل.
from aspose.cells import Workbook | |
from aspose.cells.drawing import PlacementType, SelectionType | |
from os import os, path | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Create directory if it is not already present. | |
IsExists = path.isdir(dataDir) | |
if notIsExists: | |
os.makedirs(dataDir) | |
# Create a new Workbook. | |
workbook = Workbook() | |
# Get the first worksheet. | |
sheet = workbook.worksheets[0] | |
# Get the worksheet cells collection. | |
cells = sheet.cells | |
# Input a value. | |
cells.get("B3").put_value("Choose Dept:") | |
# Set it bold. | |
cells.get("B3").get_style().font.is_bold = True | |
# Input some values that denote the input range | |
# For the list box. | |
cells.get("A2").put_value("Sales") | |
cells.get("A3").put_value("Finance") | |
cells.get("A4").put_value("MIS") | |
cells.get("A5").put_value("R&D") | |
cells.get("A6").put_value("Marketing") | |
cells.get("A7").put_value("HRA") | |
# Add a new list box. | |
listBox = sheet.shapes.add_list_box(2, 0, 3, 0, 122, 100) | |
# Set the placement type. | |
listBox.placement = PlacementType.FREE_FLOATING | |
# Set the linked cell. | |
listBox.linked_cell = "A1" | |
# Set the input range. | |
listBox.input_range = "A2:A7" | |
# Set the selection tyle. | |
listBox.selection_type = SelectionType.SINGLE | |
# Set the list box with 3-D shading. | |
listBox.shadow = True | |
# Saves the file. | |
workbook.save(dataDir + "book1.out.xls") |
إضافة عنصر تحكم زر إلى ورقة العمل
الأزرار مفيدة للقيام ببعض الإجراءات. في بعض الأحيان، من المفيد تعيين ماكرو VBA للزر أو تعيين ارتباط تشعبي لفتح صفحة ويب.
استخدام Microsoft Excel
لوضع عنصر تحكم زر في ورقة العمل الخاصة بك:
- تأكد من عرض شريط الأدوات النماذج.
- انقر على أداة الزر.
- في منطقة ورقة العمل الخاصة بك، انقر واسحب لتعريف المستطيل الذي سيحتوي على الزر.
- بمجرد وضع مربع القائمة في ورقة العمل، انقر بزر الماوس الأيمن على العنصر التحكم واختر تنسيق العنصر التحكم، ثم حدد ماكرو VBA وسمات تتعلق بالخط، التوضيب، الحجم، الهامش وما إلى ذلك.
- انقر فوق موافق.
باستخدام Aspose.Cells لبايثون via .NET
الفئة ShapeCollection توفر طريقة تسمى add_button، تستخدم لإضافة عنصر تحكم زر إلى ورقة العمل. تعيد الطريقة كائن Aspose.Cells.Drawing.Button. الفئة Aspose.Cells.Drawing.Button تمثل زرًا. لديها بعض الأعضاء الهامة:
- الخاصية text تحدد التسمية للزر.
- الخاصية font تحدد سمات الخط لتسمية عنصر تحكم الزر.
- الخاصية placement تحدد PlacementType، الطريقة التي يتم بها ربط الزر بالخلايا في ورقة العمل.
- الخاصية add_hyperlink تضيف ارتباطًا تشعبيًا لعنصر تحكم الزر. بالنقر على الزر، سيتم التنقل إلى عنوان URL ذي الصلة.
المثال التالي يوضح كيفية إضافة زر إلى ورقة العمل.
إضافة عنصر تحكم الخط إلى ورقة العمل
استخدام Microsoft Excel
- على شريط الأدوات الرسم، انقر على أشكال تلقائية, اشير إلى الخطوط, واختر نمط الخط الذي تريده.
- اسحب لرسم الخط.
- قم بإحدى الخطوتين أو كليهما:
- لتقييد رسم الخط لزوايا 15 درجة من نقطته الأولى، اضغط باستمرار على SHIFT أثناء السحب.
- لتمديد الخط في اتجاهين معاكسين من نقطة النهاية الأولى، اضغط باستمرار على CTRL أثناء السحب.
باستخدام Aspose.Cells لبايثون via .NET
توفر فئة ShapeCollection طريقة تسمى add_line، التي تُستخدم لإضافة شكل خط إلى ورقة العمل. تعيد الطريقة كائن LineShape. الفئة LineShape تمثل خطًا. لديها بعض الأعضاء الهامة:
- تحدد الطريقة line_format تنسيق الخط.
- تحدد الطريقة placement الـ PlacementType، الطريقة التي يتم بها ربط الخط بالخلايا في ورقة العمل.
توضح الأمثلة التالية كيفية إضافة خطوط إلى ورقة العمل. يتم إنشاء ثلاث خطوط بأنماط مختلفة.
from aspose.cells import Workbook | |
from aspose.cells.drawing import MsoLineDashStyle, PlacementType | |
from os import os, path | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Create directory if it is not already present. | |
IsExists = path.isdir(dataDir) | |
if notIsExists: | |
os.makedirs(dataDir) | |
# Instantiate a new Workbook. | |
workbook = Workbook() | |
# Get the first worksheet in the book. | |
worksheet = workbook.worksheets[0] | |
# Add a new line to the worksheet. | |
line1 = worksheet.shapes.add_line(5, 0, 1, 0, 0, 250) | |
# Set the line dash style | |
line1.line.dash_style = MsoLineDashStyle.SOLID | |
# Set the placement. | |
line1.placement = PlacementType.FREE_FLOATING | |
# Add another line to the worksheet. | |
line2 = worksheet.shapes.add_line(7, 0, 1, 0, 85, 250) | |
# Set the line dash style. | |
line2.line.dash_style = MsoLineDashStyle.DASH_LONG_DASH | |
# Set the weight of the line. | |
line2.line.weight = 4.0 | |
# Set the placement. | |
line2.placement = PlacementType.FREE_FLOATING | |
# Add the third line to the worksheet. | |
line3 = worksheet.shapes.add_line(13, 0, 1, 0, 0, 250) | |
# Set the line dash style | |
line3.line.dash_style = MsoLineDashStyle.SOLID | |
# Set the placement. | |
line3.placement = PlacementType.FREE_FLOATING | |
# Make the gridlines invisible in the first worksheet. | |
workbook.worksheets[0].is_gridlines_visible = False | |
# Save the excel file. | |
workbook.save(dataDir + "book1.out.xls") |
إضافة رأس سهم إلى خط
يسمح لك Aspose.Cells for Python via .NET أيضًا برسم خطوط الأسهم. من الممكن إضافة رأس سهم على خط، وتنسيق الخط. على سبيل المثال، يمكنك تغيير لون الخط، أو تحديد وزن ونمط الخط.
توضح الأمثلة التالية كيفية إضافة رأس سهم إلى خط.
from aspose.cells import Workbook | |
from aspose.cells.drawing import FillType, MsoArrowheadLength, MsoArrowheadStyle, MsoArrowheadWidth, PlacementType | |
from aspose.pydrawing import Color | |
from os import os, path | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Create directory if it is not already present. | |
IsExists = path.isdir(dataDir) | |
if notIsExists: | |
os.makedirs(dataDir) | |
# Instantiate a new Workbook. | |
workbook = Workbook() | |
# Get the first worksheet in the book. | |
worksheet = workbook.worksheets[0] | |
# Add a line to the worksheet | |
line2 = worksheet.shapes.add_line(7, 0, 1, 0, 85, 250) | |
# Set the line color | |
line2.line.fill_type = FillType.SOLID | |
line2.line.solid_fill.color = Color.blue | |
# Set the weight of the line. | |
line2.line.weight = 3.0 | |
# Set the placement. | |
line2.placement = PlacementType.FREE_FLOATING | |
# Set the line arrows. | |
line2.line.end_arrowhead_width = MsoArrowheadWidth.MEDIUM | |
line2.line.end_arrowhead_style = MsoArrowheadStyle.ARROW | |
line2.line.end_arrowhead_length = MsoArrowheadLength.MEDIUM | |
line2.line.begin_arrowhead_style = MsoArrowheadStyle.ARROW_DIAMOND | |
line2.line.begin_arrowhead_length = MsoArrowheadLength.MEDIUM | |
# Make the gridlines invisible in the first worksheet. | |
workbook.worksheets[0].is_gridlines_visible = False | |
# Save the excel file. | |
workbook.save(dataDir + "book1.out.xlsx") |
إضافة تحكم مستطيل إلى ورقة عمل
يسمح Aspose.Cells for Python via .NET برسم أشكال مستطيلة في أوراق العمل الخاصة بك. يمكنك إنشاء مستطيل، مربع، وما إلى ذلك. كما يُسمح لك بتنسيق لون التعبئة ولون خط الحد. على سبيل المثال، يمكنك تغيير لون المستطيل، وضبط لون التظليل، وتحديد وزن ونمط المستطيل حسب حاجتك.
استخدام Microsoft Excel
- في شريط الرسم، انقر فوق المستطيل.
- اسحب لرسم المستطيل.
- قم بإحدى الخطوتين أو كليهما:
- للقيد في رسم المستطيل لرسم مربع من نقطته البداية، اضغط باستمرار على SHIFT أثناء السحب.
- لرسم مستطيل من نقطة مركزية، اضغط باستمرار على CTRL أثناء السحب.
باستخدام Aspose.Cells لبايثون via .NET
توفر فئة ShapeCollection طريقة تسمى add_rectangle، التي تُستخدم لإضافة شكل مستطيل إلى ورقة عمل. تعيد الطريقة كائن Aspose.Cells.Drawing.RectangleShape. الفئة Aspose.Cells.Drawing.RectangleShape تمثل مستطيلًا. لديها بعض الأعضاء الهامة:
- يحدد الخاصية line_format سمات تنسيق الخط لمستطيل.
- يحدد الخاصية placement الـ PlacementType، الطريقة التي يتم بها ربط المستطيل بالخلايا في ورقة العمل.
- الخاصية fill_format تحدد أساليب تنسيق التعبئة الخاصة بمستطيل.
المثال التالي يظهر كيفية إضافة مستطيل إلى ورقة العمل.
from aspose.cells import Workbook | |
from aspose.cells.drawing import MsoLineDashStyle, PlacementType | |
from os import os, path | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Create directory if it is not already present. | |
IsExists = path.isdir(dataDir) | |
if notIsExists: | |
os.makedirs(dataDir) | |
# Instantiate a new Workbook. | |
excelbook = Workbook() | |
# Add a rectangle control. | |
rectangle = excelbook.worksheets[0].shapes.add_rectangle(3, 0, 2, 0, 70, 130) | |
# Set the placement of the rectangle. | |
rectangle.placement = PlacementType.FREE_FLOATING | |
# Set the line weight. | |
rectangle.line.weight = 4.0 | |
# Set the dash style of the rectangle. | |
rectangle.line.dash_style = MsoLineDashStyle.SOLID | |
# Save the excel file. | |
excelbook.save(dataDir + "book1.out.xls") |
إضافة تحكم بالقوس إلى ورقة العمل
يسمح Aspose.Cells for Python via .NET برسم أشكال قوس في أوراق العمل الخاصة بك. يمكنك إنشاء أقواس بسيطة ومملوءة. يُسمح لك بتنسيق لون التعبئة ولون خط الحد للتحكم. على سبيل المثال، يمكنك تحديد / تغيير لون القوس، وضبط لون التظليل، وتحديد وزن ونمط الشكل حسب حاجتك.
استخدام Microsoft Excel
- على شريط الأدوات الرسم، انقر على القوس في الأشكال التلقائية.
- اسحب لرسم القوس.
باستخدام Aspose.Cells لبايثون via .NET
توفر الفئة ShapeCollection طريقة بعنوان add_arc، والتي تُستخدم لإضافة شكل قوس إلى ورقة عمل. تُرجع الطريقة كائنًا من النوع Aspose.Cells.Drawing.ArcShape. تُمثل الفئة Aspose.Cells.Drawing.ArcShape قوسًا. ولها بعض الأعضاء المهمة:
- الخاصية line_format تحدد سمات تنسيق الخط الخاصة بشكل القوس.
- الخاصية placement تحدد PlacementType، الطريقة التي يتم بها إرفاق القوس بالخلايا في ورقة العمل.
- خاصية fill_format تحدد أنماط تنسيق التعبئة للشكل.
- تحدد خاصية lower_right_row مؤشر الصف الأيمن الأدنى.
- تحدد خاصية lower_right_column مؤشر العمود الأيمن الأدنى.
المثال التالي يظهر كيفية إضافة أشكال قوسية إلى ورقة العمل. ينشئ المثال شكلين قوسيين: أحدهما ممتلئ والآخر بسيط.
from aspose.cells import Workbook | |
from aspose.cells.drawing import FillType, MsoLineDashStyle, PlacementType | |
from aspose.pydrawing import Color | |
from os import os, path | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Create directory if it is not already present. | |
IsExists = path.isdir(dataDir) | |
if notIsExists: | |
os.makedirs(dataDir) | |
# Instantiate a new Workbook. | |
excelbook = Workbook() | |
# Add an arc shape. | |
arc1 = excelbook.worksheets[0].shapes.add_arc(2, 0, 2, 0, 130, 130) | |
# Set the fill shape color | |
arc1.fill.fill_type = FillType.SOLID | |
arc1.fill.solid_fill.color = Color.blue | |
# Set the placement of the arc. | |
arc1.placement = PlacementType.FREE_FLOATING | |
# Set the line weight. | |
arc1.line.weight = 1.0 | |
# Set the dash style of the arc. | |
arc1.line.dash_style = MsoLineDashStyle.SOLID | |
# Add another arc shape. | |
arc2 = excelbook.worksheets[0].shapes.add_arc(9, 0, 2, 0, 130, 130) | |
# Set the line color | |
arc2.line.fill_type = FillType.SOLID | |
arc2.line.solid_fill.color = Color.blue | |
# Set the placement of the arc. | |
arc2.placement = PlacementType.FREE_FLOATING | |
# Set the line weight. | |
arc2.line.weight = 1.0 | |
# Set the dash style of the arc. | |
arc2.line.dash_style = MsoLineDashStyle.SOLID | |
# Save the excel file. | |
excelbook.save(dataDir + "book1.out.xls") |
إضافة تحكم بالشكل البيضوي إلى ورقة عمل
يسمح Aspose.Cells for Python via .NET برسم أشكال بيضاوية في أوراق العمل. إنشاء أشكال بيضاوية بسيطة ومملوءة وتنسيق لون التعبئة ولون خط الحد للتحكم. على سبيل المثال، يمكنك تحديد / تغيير لون الشكل البيضاوي، وضبط لون التظليل، وتحديد وزن ونمط الشكل حسب حاجتك.
استخدام Microsoft Excel
- على شريط الأدوات الرسم، انقر على البيضوي.
- اسحب لرسم البيضوي.
- قم بأحد أو كل من الآتي:
- لتقييد الشكل البيضاوي لرسم دائرة من نقطته البدء، اضغط على مفتاح SHIFT أثناء سحبه.
- لرسم شكل بيضاوي من نقطة مركزية، اضغط على CTRL أثناء سحبه.
باستخدام Aspose.Cells لبايثون via .NET
تقدم فئة ShapeCollection طريقة تسمى add_oval، التي تُستخدم لإضافة شكل بيضوي إلى ورقة العمل. تُرجع الطريقة كائن Aspose.Cells.Drawing.Oval. الفئة Aspose.Cells.Drawing.Oval تمثل شكل بيضوي. لها بعض الأعضاء الهامة:
- تحدد خاصية line_format سمات تنسيق الخط لشكل بيضوي.
- خاصية placement تحدد PlacementType، الطريقة التي يتم فيها تعلق الشكل البيضاوي بالخلايا في ورقة العمل.
- خاصية fill_format تحدد أنماط تنسيق التعبئة للشكل.
- تحدد خاصية lower_right_row مؤشر الصف الأيمن الأدنى.
- تحدد خاصية lower_right_column مؤشر العمود الأيمن الأدنى.
المثال التالي يوضح كيفية إضافة أشكال بيضوية إلى ورقة العمل. ينشئ المثال شكلين بيضويين: أحدهما ممتلئ والآخر هو دائرة بسيطة.
from aspose.cells import Workbook | |
from aspose.cells.drawing import MsoLineDashStyle, PlacementType | |
from os import os, path | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Create directory if it is not already present. | |
IsExists = path.isdir(dataDir) | |
if notIsExists: | |
os.makedirs(dataDir) | |
# Instantiate a new Workbook. | |
excelbook = Workbook() | |
# Add an oval shape. | |
oval1 = excelbook.worksheets[0].shapes.add_oval(2, 0, 2, 0, 130, 160) | |
# Set the placement of the oval. | |
oval1.placement = PlacementType.FREE_FLOATING | |
# Set the line weight. | |
oval1.line.weight = 1.0 | |
# Set the dash style of the oval. | |
oval1.line.dash_style = MsoLineDashStyle.SOLID | |
# Add another oval (circle) shape. | |
oval2 = excelbook.worksheets[0].shapes.add_oval(9, 0, 2, 15, 130, 130) | |
# Set the placement of the oval. | |
oval2.placement = PlacementType.FREE_FLOATING | |
# Set the line weight. | |
oval2.line.weight = 1.0 | |
# Set the dash style of the oval. | |
oval2.line.dash_style = MsoLineDashStyle.SOLID | |
# Save the excel file. | |
excelbook.save(dataDir + "book1.out.xls") |
إضافة عنصر تحكم Spinner إلى ورقة العمل
صندوق التدوير هو مربع نص مرتبط بزر (يسمى زر التدوير) يتكون من سهم لأعلى وسهم لأسفل يمكنك النقر عليه لتغيير القيمة تدريجيًا في مربع النص. باستخدام صناديق التدوير، يمكنك رؤية كيف ستؤثر تغييرات الإدخال على نموذجك المالي على مخرجات النموذج. يمكنك ربط زر التدوير بخلية إدخال معينة. أثناء النقر على السهم للأعلى أو لأسفل على زر التدوير، تزداد أو تتناقص القيمة الصحيحة في خلية الإدخال المستهدفة. يسمح Aspose.Cells for Python via .NET بإنشاء أزرار تدوير في أوراق العمل الخاصة بك.
استخدام Microsoft Excel
لوضع عنصر تحكم مربع الدوران في ورقة العمل الخاصة بك:
- تأكد من عرض شريط الأدوات النماذج.
- انقر فوق أداة Spinner.
- في منطقة ورقة العمل، انقر واسحب لتحديد المستطيل الذي سيحتوي على عنصر التحكم.
- بمجرد وضع عنصر التحكم في ورقة العمل، انقر بزر الفأرة الأيمن على العنصر التحكم وانقر على تنسيق التحكم وحدد القيم القصوى والصغرى والقيم التزايدية.
- في حقل ارتباط الخلية، حدد عنوان الخلية التي يجب أن يكون مربع الدوران مرتبط بها.
- انقر فوق موافق.
باستخدام Aspose.Cells لبايثون via .NET
فئة ShapeCollection تُوفر طريقة تسمى add_spinner، والتي تُستخدم لإضافة عنصر تحكم مربع دوراني إلى ورقة العمل. تُرجِع الطريقة كائن Aspose.Cells.Drawing.Spinner. الفئة Aspose.Cells.Drawing.Spinner تمثل مربع دوراني. لديها بعض الأعضاء الهامة:
- يحدد الخاصية linked_cell الخلية المرتبطة بمربع الدوران.
- يحدد الخاصية max القيمة القصوى لنطاق مربع الدوران.
- يحدد الخاصية min القيمة الدنيا لنطاق مربع الدوران.
- يحدد الخاصية incremental_change كمية القيمة التي يتم زيادتها عند التمرير بخطوة واحدة.
- تشير الخاصية shadow ما إذا كان مربع الدوران يحتوي على تظليل ثلاثي الأبعاد.
- يحدد الخاصية current_value القيمة الحالية لمربع الدوران.
المثال التالي يوضح كيفية إضافة مربع دوراني إلى ورقة العمل.
from aspose.cells import BackgroundType, Workbook | |
from aspose.cells.drawing import PlacementType | |
from aspose.pydrawing import Color | |
from os import os, path | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Create directory if it is not already present. | |
IsExists = path.isdir(dataDir) | |
if notIsExists: | |
os.makedirs(dataDir) | |
# Instantiate a new Workbook. | |
excelbook = Workbook() | |
# Get the first worksheet. | |
worksheet = excelbook.worksheets[0] | |
# Get the worksheet cells. | |
cells = worksheet.cells | |
# Input a string value into A1 cell. | |
cells.get("A1").put_value("Select Value:") | |
# Set the font color of the cell. | |
cells.get("A1").get_style().font.color = Color.red | |
# Set the font text bold. | |
cells.get("A1").get_style().font.is_bold = True | |
# Input value into A2 cell. | |
cells.get("A2").put_value(0) | |
# Set the shading color to black with solid background. | |
cells.get("A2").get_style().foreground_color = Color.black | |
cells.get("A2").get_style().pattern = BackgroundType.SOLID | |
# Set the font color of the cell. | |
cells.get("A2").get_style().font.color = Color.white | |
# Set the font text bold. | |
cells.get("A2").get_style().font.is_bold = True | |
# Add a spinner control. | |
spinner = excelbook.worksheets[0].shapes.add_spinner(1, 0, 1, 0, 20, 18) | |
# Set the placement type of the spinner. | |
spinner.placement = PlacementType.FREE_FLOATING | |
# Set the linked cell for the control. | |
spinner.linked_cell = "A2" | |
# Set the maximum value. | |
spinner.max = 10 | |
# Set the minimum value. | |
spinner.min = 0 | |
# Set the incr. change for the control. | |
spinner.incremental_change = 2 | |
# Set it 3-D shading. | |
spinner.shadow = True | |
# Save the excel file. | |
excelbook.save(dataDir + "book1.out.xls") |
إضافة عنصر تحكم شريط التمرير إلى ورقة العمل
يُستخدم عنصر التحكم بشريط التمرير لمساعدة في تحديد البيانات على ورقة العمل بشكل مماثل لعنصر تحكم مربع الدوران. من خلال إضافة العنصر التحكم إلى ورقة العمل وربطه بخلية، يكون من الممكن العودة بقيمة رقمية للموضع الحالي للعنصر التحكم.
استخدام Microsoft Excel
- لإضافة شريط تمرير في Excel 2003 والإصدارات السابقة، انقر فوق زر شريط التمرير على شريط الأدوات النماذج، ثم أنشئ شريط تمرير يغطي الخلايا B2:B6 في الارتفاع ويكون بنسبة رُبع عرض العمود.
- لإضافة شريط تمرير في Excel 2007، انقر فوق علامة المطور، ثم انقر على إدراج، ومن ثم انقر على شريط التمرير في قسم عناصر النماذج.
- انقر بزر الماوس الأيمن على شريط التمرير، ومن ثم انقر فوق تنسيق الضبط.
- اكتب المعلومات التالية، وانقر فوق موافق:
- في مربع القيمة الحالية، اكتب 1.
- في مربع القيمة الدنيا، اكتب 1. يحدد هذا القيمة الحد الأقصى لشريط التمرير لأول عنصر في القائمة.
- في مربع القيمة القصوى، اكتب 20. تُحدد هذه الرقم الحد الأقصى لعدد الإدخالات في القائمة.
- في مربع التغيير التدريجي، اكتب 1. تحكم هذه القيمة في كم عدد الأرقام التي يزيد بها تحكم شريط التمرير القيمة الحالية.
- في مربع تغيير الصفحة، اكتب 5. تحكم هذا الإدخال في مقدار زيادة القيمة الحالية إذا نقرت داخل شريط التمرير على أي جانب من جوانب المربع التمرير.
- لوضع قيمة رقمية في الخلية G1 (تبعًا للعنصر المحدد في القائمة)، اكتب G1 في مربع الرابط الخلوي.
- انقر فوق أي خلية بحيث لا يتم تحديد شريط التمرير.
عندما تنقر فوق التحكم بتحريك لأعلى أو لأسفل على شريط التمرير، يتم تحديث الخلية G1 إلى الرقم الذي يشير إلى القيمة الحالية لشريط التمرير بالإضافة إلى أو ناقص تغيير التحكم التدريجي لشريط التمرير.
باستخدام Aspose.Cells لبايثون via .NET
يوفر الفصيلة ShapeCollection طريقة تُدعى add_scroll_bar، والتي تُستخدم لإضافة تحكم شريط التمرير إلى ورقة العمل. تُرجع الطريقة كائن Aspose.Cells.Drawing.ScrollBar. الفصيلة Aspose.Cells.Drawing.ScrollBar تُمثل تحكم شريط التمرير. لها بعض الأعضاء المهمة:
- تحدد الخاصية linked_cell الخلية المرتبطة بشريط التمرير.
- تحدد الخاصية max القيمة القصوى لنطاق شريط التمرير.
- تحدد الخاصية min القيمة الدنيا لنطاق شريط التمرير.
- تحدد الخاصية incremental_change مقدار القيمة الذي يتم به زيادة شريط التمرير بتمريرة.
- توضح الخاصية shadow ما إذا كان لشريط التمرير تظليل ثلاثي الأبعاد أم لا.
- تحدد الخاصية current_value القيمة الحالية لشريط التمرير.
- تحدد الخاصية page_change مقدار زيادة القيمة الحالية إذا نقرت داخل شريط التمرير على أي جانب من جوانب المربع التمرير.
المثال التالي يظهر كيفية إضافة شريط تمرير إلى ورقة العمل.
from aspose.cells import Workbook | |
from aspose.cells.drawing import PlacementType | |
from aspose.pydrawing import Color | |
from os import os, path | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Create directory if it is not already present. | |
IsExists = path.isdir(dataDir) | |
if notIsExists: | |
os.makedirs(dataDir) | |
# Instantiate a new Workbook. | |
excelbook = Workbook() | |
# Get the first worksheet. | |
worksheet = excelbook.worksheets[0] | |
# Invisible the gridlines of the worksheet. | |
worksheet.is_gridlines_visible = False | |
# Get the worksheet cells. | |
cells = worksheet.cells | |
# Input a value into A1 cell. | |
cells.get("A1").put_value(1) | |
# Set the font color of the cell. | |
cells.get("A1").get_style().font.color = Color.maroon | |
# Set the font text bold. | |
cells.get("A1").get_style().font.is_bold = True | |
# Set the number format. | |
cells.get("A1").get_style().number = 1 | |
# Add a scrollbar control. | |
scrollbar = worksheet.shapes.add_scroll_bar(0, 0, 1, 0, 125, 20) | |
# Set the placement type of the scrollbar. | |
scrollbar.placement = PlacementType.FREE_FLOATING | |
# Set the linked cell for the control. | |
scrollbar.linked_cell = "A1" | |
# Set the maximum value. | |
scrollbar.max = 20 | |
# Set the minimum value. | |
scrollbar.min = 1 | |
# Set the incr. change for the control. | |
scrollbar.incremental_change = 1 | |
# Set the page change attribute. | |
scrollbar.page_change = 5 | |
# Set it 3-D shading. | |
scrollbar.shadow = True | |
# Save the excel file. | |
excelbook.save(dataDir + "book1.out.xls") |
إضافة تحكم مجموعة إلى تحكمات المجموعة في ورقة عمل
في بعض الأحيان قد تحتاج إلى تنفيذ أزرار الراديو أو تحكمات أخرى تنتمي إلى مجموعة معينة، يمكنك تنفيذ ذلك من خلال تضمين إما مربع مجموعة أو تحكم مستطيل. يمكن لأي من هاتين الشكلين أن يكون محدد المجموعة. بعد إضافة أحد هاتين الشكلين، يمكنك بعد ذلك إضافة اثنين أو أكثر من أزرار الراديو أو أجهزة مجموعة أخرى.
استخدام Microsoft Excel
لوضع تحكم مربع المجموعة في ورقة العمل الخاصة بك ووضع تحكمات فيه:
- لبدء النموذج، على القائمة الرئيسية، انقر فوق عرض، ثم شرائط الأدوات، ثم نماذج.
- في شريط الأدوات النماذج، انقر فوق مربع التجميع وارسم مستطيلًا على ورقة العمل.
- اكتب سلسلة تسمية للمربع.
- في شريط أدوات النماذج، انقر فوق زر الاختيار وانقر داخل مربع التجميع مباشرة تحت سلسلة التسمية.
- من شريط الأدوات النماذج مرة أخرى، انقر زر الاختيار وانقر داخل مربع التجميع تحت الزر الإشعاري الأول.
- مرة أخرى على شريط الأدوات النماذج، انقر فوق زر الاختيار وانقر داخل مربع التجميع تحت الزر الإشعاري السابق.
باستخدام Aspose.Cells لبايثون via .NET
توفر فئة ShapeCollection الأسلوب المسمى add_group_box، والذي يُستخدم لإضافة عنصر تحكم مربع تجميع إلى ورقة العمل. يُرجع الأسلوب كائن Aspose.Cells.Drawing.GroupBox. علاوة على ذلك، فإن الأسلوب group لفئة ShapeCollection يجمع بين الأشكال، حيث يأخذ مصفوفة Shape كمعلمة ويُرجع كائن GroupShape. تمثل الفئة Aspose.Cells.Drawing.GroupBox مربع تجميع. تحتوي على بعض الأعضاء المهمة:
- تحدد الخاصية text سلسة تسمية مربع التجميع.
- تشير الخاصية shadow ما إذا كان مربع التجميع لديه تظليل ثلاثي الأبعاد.
المثال التالي يُظهر كيفية إضافة مربع تجميع وتجميع عناصر التحكم في ورقة العمل.
from aspose.cells import Workbook | |
from aspose.cells.drawing import MsoLineDashStyle, PlacementType | |
from os import os, path | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Create directory if it is not already present. | |
IsExists = path.isdir(dataDir) | |
if notIsExists: | |
os.makedirs(dataDir) | |
# Instantiate a new Workbook. | |
excelbook = Workbook() | |
# Add a group box to the first worksheet. | |
box = excelbook.worksheets[0].shapes.add_group_box(1, 0, 1, 0, 300, 250) | |
# Set the caption of the group box. | |
box.text = "Age Groups" | |
box.placement = PlacementType.FREE_FLOATING | |
# Make it 2-D box. | |
box.shadow = False | |
# Add a radio button. | |
radio1 = excelbook.worksheets[0].shapes.add_radio_button(3, 0, 2, 0, 30, 110) | |
# Set its text string. | |
radio1.text = "20-29" | |
# Set A1 cell as a linked cell for the radio button. | |
radio1.linked_cell = "A1" | |
# Make the radio button 3-D. | |
radio1.shadow = True | |
# Set the weight of the radio button. | |
radio1.line.weight = 4.0 | |
# Set the dash style of the radio button. | |
radio1.line.dash_style = MsoLineDashStyle.SOLID | |
# Add another radio button. | |
radio2 = excelbook.worksheets[0].shapes.add_radio_button(6, 0, 2, 0, 30, 110) | |
# Set its text string. | |
radio2.text = "30-39" | |
# Set A1 cell as a linked cell for the radio button. | |
radio2.linked_cell = "A1" | |
# Make the radio button 3-D. | |
radio2.shadow = True | |
# Set the weight of the radio button. | |
radio2.line.weight = 4.0 | |
# Set the dash style of the radio button. | |
radio2.line.dash_style = MsoLineDashStyle.SOLID | |
# Add another radio button. | |
radio3 = excelbook.worksheets[0].shapes.add_radio_button(9, 0, 2, 0, 30, 110) | |
# Set its text string. | |
radio3.text = "40-49" | |
# Set A1 cell as a linked cell for the radio button. | |
radio3.linked_cell = "A1" | |
# Make the radio button 3-D. | |
radio3.shadow = True | |
# Set the weight of the radio button. | |
radio3.line.weight = 4.0 | |
# Set the dash style of the radio button. | |
radio3.line.dash_style = MsoLineDashStyle.SOLID | |
# Get the shapes. | |
shapeobjects = [box, radio1, radio2, radio3] | |
# Group the shapes. | |
group = excelbook.worksheets[0].shapes.group(shapeobjects) | |
# Save the excel file. | |
excelbook.save(dataDir + "book1.out.xls") |