إعدادات المحاذاة

ضبط إعدادات المحاذاة

إعدادات المحاذاة في Microsoft Excel

أي شخص قد استخدم Microsoft Excel لتنسيق الخلايا سيكون متعودًا على إعدادات المحاذاة في Microsoft Excel.

كما يمكنك رؤية من الشكل أعلاه، هناك أنواع مختلفة من خيارات المحاذاة:

  • محاذاة النص (أفقية وعمودية)
  • المسافة البادئة.
  • التوجيه.
  • التحكم بالنص.
  • اتجاه النص.

كل إعدادات المحاذاة هذه مدعومة تمامًا بواسطة Aspose.Cells ويتم مناقشتها بمزيد من التفصيل أدناه.

إعدادات المحاذاة في Aspose.Cells

توفر Aspose.Cells الأساليب GetStyle و SetStyle لفئة Cell والتي تُستخدم للحصول على تنسيق الخلية وتعيينه. توفر الفئة Style خصائص مفيدة لتكوين إعدادات المحاذاة.

حدد أي نوع لمحاذاة النص باستخدام تعداد TextAlignmentType. أنواع محاذاة النص المحددة مسبقًا في تعداد TextAlignmentType هي:

** أنواع محاذاة النص ** ** الوصف **
Bottom يمثل محاذاة النص السفلي
Center يمثل محاذاة النص الوسطية
CenterAcross تمثل محاذاة النص في وسط النص
Distributed تمثل توزيع محاذاة النص
Fill تمثل ملء محاذاة النص
General تمثل محاذاة النص العامة
Justify تمثل محاذاة النص التبريري
Left يمثل محاذاة النص اليسار
Right يمثل محاذاة النص اليمين
Top يمثل محاذاة النص العلوي
JustifiedLow يُحاذي النص بطول كاشيدا معدل للنص العربي.
ThaiDistributed يوزع النص التايلاندي خصوصًا، لأن كل حرف يُعامل ككلمة.

المحاذاة الأفقية والرأسية والمسافة البادئة

استخدم الخاصية HorizontalAlignment لمحاذاة النص أفقيًا والخاصية VerticalAlignment لمحاذاة النص عموديًا. من الممكن تعيين مستوى البادئة للنص في الخلية باستخدام الخاصية IndentLevel ويؤثر ذلك فقط عندما تكون المحاذاة الأفقية يمينًا أو يسارًا.

// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Obtaining the reference of first worksheet
Worksheet worksheet = workbook.getWorksheets().get(0);
// Accessing the "A1" cell from the worksheet
Cell cell = worksheet.getCells().get("A1");
// Adding some value to the "A1" cell
cell.putValue("Visit Aspose!");
// Setting the horizontal alignment of the text in the "A1" cell
Style style = cell.getStyle();
//Set text left horizontal alignment
style.setHorizontalAlignment(TextAlignmentType.RIGHT);
//Set indent
style.setIndentLevel(4);
//Set text top vertical alignment
style.setVerticalAlignment(TextAlignmentType.TOP);
cell.setStyle(style);
// Saving the Excel file
workbook.save("book1.xlsx");

الاتجاه

قم بتعيين الاتجاه (الدوران) للنص في خلية باستخدام الخاصية RotationAngle.

// Accessing the "A1" cell from the worksheet
Cell cell = worksheet.getCells().get("A1");
// Adding some value to the "A1" cell
cell.putValue("Visit Aspose!");
// Setting the horizontal alignment of the text in the "A1" cell
Style style = cell.getStyle();
// Setting the rotation of the text (inside the cell) to 25
style.setRotationAngle(25);
cell.setStyle(style);
//Accessing the "A2" cell from the worksheet
cell = worksheet.getCells().get("A2");
// Adding some value to the "A1" cell
cell.putValue("Visit Aspose!");
// Setting the horizontal alignment of the text in the "A2" cell
style = cell.getStyle();
// Setting the orientation of the text from top to bottom
style.setRotationAngle(255);
cell.setStyle(style);
// Saving the Excel file
workbook.save("book1.xlsx");

التحكم في النص

يناقش القسم التالي كيفية التحكم في النص عن طريق تعيين التفاف النص، وتقليل حجم النص للتناسب وخيارات التنسيق الأخرى.

تفاف النص

تجعل التفاف النص في خلية أمر قراءته أسهل: يتكيف ارتفاع الخلية ليتناسب مع كل النص بدلاً من قطعه أو تسربه إلى الخلايا المجاورة. قم بتعيين تفاف النص على أو قبالة باستخدام الخاصية IsTextWrapped.

// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Obtaining the reference of first worksheet
Worksheet worksheet = workbook.getWorksheets().get(0);
// Accessing the "A1" cell from the worksheet
Cell cell = worksheet.getCells().get("A1");
// Adding some value to the "A1" cell
cell.putValue("I am using the latest version of Aspose.Cells to test this functionality.");
// Gets style
Style style = cell.getStyle();
// Wrap Cell's Text wrap
style.setTextWrapped( true);
//Set style.
cell.setStyle(style);
// Saving the Excel file
workbook.save("book1.xlsx");

تقليص للتناسب

خيار لتفاف النص في الحقل هو تصغير حجم النص ليتناسب مع أبعاد الخلية. يتم ذلك عن طريق تعيين الخاصية ShrinkToFit. إلى true.

// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Obtaining the reference of first worksheet
Worksheet worksheet = workbook.getWorksheets().get(0);
// Accessing the "A1" cell from the worksheet
Cell cell = worksheet.getCells().get("A1");
// Adding some value to the "A1" cell
cell.putValue("I am using the latest version of Aspose.Cells to test this functionality.");
// Gets style in the "A1" cell
Style style = cell.getStyle();
// Shrinking the text to fit according to the dimensions of the cell
style.setShrinkToFit(true);
cell.setStyle(style);
// Saving the Excel file
workbook.save("book1.xlsx");

دمج الخلايا

مثل Microsoft Excel، تدعم Aspose.Cells دمج عدة خلايا في خلية واحدة. توفر Aspose.Cells طريقتين لهذه المهمة. الطريقة الأولى هي استدعاء الطريقة Merge. تأخذ الطريقة المعلمات التالية لدمج الخلايا:

  • الصف الأول: الصف الأول من حيث بدء الدمج.
  • العمود الأول: العمود الأول من حيث بدء الدمج.
  • عدد الصفوف: عدد الصفوف التي تم دمجها.
  • عدد الأعمدة: عدد الأعمدة المدمجة.
// Create a Cells object ot fetch all the cells.
Cells cells = worksheet.getCells();
// Merge some Cells (C6:E7) into a single C6 Cell.
cells.merge(5, 2, 2, 3);
// Input data into C6 Cell.
worksheet.getCells().get(5, 2).putValue("This is my value");
// Create a Style object to fetch the Style of C6 Cell.
Style style = worksheet.getCells().get(5, 2).getStyle();
// Create a Font object
Font font = style.getFont();
// Set the name.
font.setName("Times New Roman");
// Set the font size.
font.setSize(18);
// Set the font color
font.setColor(Color.getBlue());
// Bold the text
font.setBold(true);
// Make it italic
font.setItalic(true);
// Set the backgrond color of C6 Cell to Red
style.setForegroundColor(Color.getRed());
style.setPattern(BackgroundType.SOLID);
// Apply the Style to C6 Cell.
cells.get(5, 2).setStyle(style);

اتجاه النص

من الممكن تعيين ترتيب قراءة النص في الخلايا. ترتيب القراءة هو الترتيب البصري الذي يظهر فيه الأحرف والكلمات وما إلى ذلك. على سبيل المثال، الإنجليزية هي لغة من اليسار إلى اليمين بينما العربية هي لغة من اليمين إلى اليسار.

يتم تحديد ترتيب القراءة بواسطة خاصية TextDirection. يوفر Aspose.Cells أنواع توجيه النص المحددة مسبقًا في تعداد TextDirectionType.

أنواع توجيه النص الوصف
Context ترتيب القراءة متسق مع لغة الحرف الأول المُدخل
LeftToRight الترتيب من اليسار إلى اليمين
RightToLeft الترتيب من اليمين إلى اليسار
// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Obtaining the reference of first worksheet
Worksheet worksheet = workbook.getWorksheets().get(0);
// Accessing the "A1" cell from the worksheet
Cell cell = worksheet.getCells().get("A1");
// Adding some value to the "A1" cell
cell.putValue("I am using the latest version of Aspose.Cells to test this functionality.");
// Gets style in the "A1" cell
Style style = cell.getStyle();
// Shrinking the text to fit according to the dimensions of the cell
style.setTextDirection(TextDirectionType.LEFT_TO_RIGHT);
cell.setStyle(style);
// Saving the Excel file
workbook.save("book1.xlsx");

مواضيع متقدمة