كيفية تطبيق / تحديد محاذاة النص لمربع النص
يمكن أن تحسن مربعات النص تعبيرات وثائقنا ورسوماتنا ، وتطبيق تحاذية مختلفة لأجزاء مختلفة من مربع النص يمكن أن يساعد في تسليط الضوء على نقاط الاهتمام للقراء. ولكن المحاذاة الافتراضية لمربع النص لا تلبي كل احتياجاتنا. لهذا ، قد تحتاج إلى ضبط كل مربع نص لتلبية متطلباتك المستهدفة. إذا لم يكن لديك الكثير من كائنات مربع النص لتعديلها، فأنت محظوظ. إذا كان هناك الكثير من مربعات النص لضبطها، أعتقد أنك ستكون في مأزق. لا تقلق الآن، Aspose.Cells يوفر واجهة برمجية لتساعدك في فعل ذلك تماماً.
يطبق الكود النموذجي التالي تحديد محاذاة النص على مربع نص.
from aspose.cells import TextAlignmentType, 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 = "" | |
if notpath.isdir(dataDir): | |
os.makedirs(dataDir) | |
# Instantiating a Workbook object | |
workbook = Workbook() | |
shapes = workbook.worksheets[0].shapes | |
# add a TextBox | |
shape = shapes.add_text_box(2, 0, 2, 0, 50, 120) | |
shape.text = "This is a test." | |
# set alignment | |
shape.text_horizontal_alignment = TextAlignmentType.CENTER | |
shape.text_vertical_alignment = TextAlignmentType.CENTER | |
# Save the excel file. | |
workbook.save(dataDir + "result.xlsx") |
يمكنك أيضًا تغيير محاذاة النص داخل شكل مربع النص باستخدام النص HTML المناسب. الكود النموذجي التالي يطبق تحديد محاذاة النص على النص الجزئي داخل مربع النص.
from aspose import pycore | |
from aspose.cells import Workbook | |
from aspose.cells.drawing import MsoDrawingType, TextBox | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# Intialize an object of the Workbook class to load template file | |
sourceWb = Workbook("SampleTextboxExcel2016.xlsx") | |
# Access the target textbox whose text is to be aligned | |
sourceTextBox = sourceWb.worksheets[0].shapes[0] | |
# Create and object of the target workbook | |
destWb = Workbook() | |
# Access first worksheet from the collection | |
_sheet = destWb.worksheets[0] | |
# Create new textbox | |
_textBox = pycore.cast(TextBox, _sheet.shapes.add_shape(MsoDrawingType.TEXT_BOX, 1, 0, 1, 0, 200, 200)) | |
# Alternatively text box can be added using following line as well | |
# TextBox _textBox = _sheet.Shapes.AddTextBox(1, 0, 1, 0, 200, 200); | |
# Use Html string from a template file textbox | |
_textBox.html_text = sourceTextBox.html_text | |
# Save the workbook on disc | |
destWb.save("Output.xlsx") |