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

تكوين إعدادات المحاذاة

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

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

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

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

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

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

Aspose.Cells يوفر فصل دراسي ،دفتر العمل ، يمثل ملف Excel. الدفتر العمل فئة تحتوي علىأوراق عمل مجموعة تسمح بالوصول إلى كل ورقة عمل في ملف Excel. يتم تمثيل ورقة العمل بواسطةورقة عمل صف دراسي. الورقة عمل فئة توفر أCells مجموعة. كل عنصر فيCells تمثل المجموعة كائنًا منCellصف دراسي.

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

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

أنواع محاذاة النص وصف
قاع يمثل محاذاة النص السفلي
مركز يمثل مركز محاذاة النص
CenterAcross يمثل المركز عبر محاذاة النص
وزعت يمثل محاذاة النص الموزع
ملء يمثل محاذاة النص التعبئة
عام يمثل محاذاة نص عامة
يبرر التمثيلات تضبط محاذاة النص
اليسار يمثل محاذاة النص الأيسر
الصحيح يمثل محاذاة النص الصحيحة
قمة يمثل محاذاة النص العلوي
مبرر منخفض يحاذي النص بطول الكشيدة المعدل للنص العربي.
التايلاندية الموزعة يوزع النص التايلاندي بشكل خاص ، لأنه يتم التعامل مع كل حرف على أنه كلمة.

المحاذاة الأفقية

استخدم الأسلوب أشياءالمحاذاة الأفقيةلمحاذاة النص أفقيًا.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Create directory if it is not already present.
bool IsExists = System.IO.Directory.Exists(dataDir);
if (!IsExists)
System.IO.Directory.CreateDirectory(dataDir);
// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Obtaining the reference of the worksheet
Worksheet worksheet = workbook.Worksheets[0];
// Accessing the "A1" cell from the worksheet
Aspose.Cells.Cell cell = worksheet.Cells["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();
style.HorizontalAlignment = TextAlignmentType.Center;
cell.SetStyle(style);
// Saving the Excel file
workbook.Save(dataDir + "book1.out.xls", SaveFormat.Excel97To2003);

انحياز عمودي

على غرار المحاذاة الأفقية ، استخدمأسلوب أشياءانحياز عموديلمحاذاة النص عموديًا.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Create directory if it is not already present.
bool IsExists = System.IO.Directory.Exists(dataDir);
if (!IsExists)
System.IO.Directory.CreateDirectory(dataDir);
// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Clearing all the worksheets
workbook.Worksheets.Clear();
// Adding a new worksheet to the Excel object
int i = workbook.Worksheets.Add();
// Obtaining the reference of the newly added worksheet by passing its sheet index
Worksheet worksheet = workbook.Worksheets[i];
// Accessing the "A1" cell from the worksheet
Aspose.Cells.Cell cell = worksheet.Cells["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 vertical alignment of the text in a cell
style.VerticalAlignment = TextAlignmentType.Center;
cell.SetStyle(style);
// Saving the Excel file
workbook.Save(dataDir + "book1.out.xls", SaveFormat.Excel97To2003);

المسافة الفارغة

من الممكن تعيين مستوى المسافة البادئة للنص في خلية بامتدادأسلوب أشياءمستوى المسافة البادئةخاصية.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Create directory if it is not already present.
bool IsExists = System.IO.Directory.Exists(dataDir);
if (!IsExists)
System.IO.Directory.CreateDirectory(dataDir);
// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Obtaining the reference of the worksheet
Worksheet worksheet = workbook.Worksheets[0];
// Accessing the "A1" cell from the worksheet
Aspose.Cells.Cell cell = worksheet.Cells["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 indentation level of the text (inside the cell) to 2
style.IndentLevel = 2;
cell.SetStyle(style);
// Saving the Excel file
workbook.Save(dataDir + "book1.out.xls", SaveFormat.Excel97To2003);

اتجاه

عيّن اتجاه (تدوير) النص في خلية بامتدادأسلوب أشياءزاوية الدورانخاصية.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Create directory if it is not already present.
bool IsExists = System.IO.Directory.Exists(dataDir);
if (!IsExists)
System.IO.Directory.CreateDirectory(dataDir);
// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Obtaining the reference of the worksheet
Worksheet worksheet = workbook.Worksheets[0];
// Accessing the "A1" cell from the worksheet
Aspose.Cells.Cell cell = worksheet.Cells["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.RotationAngle = 25;
cell.SetStyle(style);
// Saving the Excel file
workbook.Save(dataDir + "book1.out.xls", SaveFormat.Excel97To2003);

التحكم بالنص

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

التفاف النص

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

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Create Workbook Object
Workbook wb = new Workbook();
// Open first Worksheet in the workbook
Worksheet ws = wb.Worksheets[0];
// Get Worksheet Cells Collection
Aspose.Cells.Cells cell = ws.Cells;
// Increase the width of First Column Width
cell.SetColumnWidth(0, 35);
// Increase the height of first row
cell.SetRowHeight(0, 36);
// Add Text to the Firts Cell
cell[0, 0].PutValue("I am using the latest version of Aspose.Cells to test this functionality");
// Make Cell's Text wrap
Style style = cell[0, 0].GetStyle();
style.IsTextWrapped = true;
cell[0, 0].SetStyle(style);
// Save Excel File
wb.Save(dataDir+ "WrappingText.out.xlsx");
تقلص لتناسب

يتمثل أحد خيارات التفاف النص في حقل في تقليص حجم النص ليلائم أبعاد الخلية. يتم ذلك عن طريق تحديد ملفأسلوب أشياءIsTextWrapped ملكية لحقيقي.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Create directory if it is not already present.
bool IsExists = System.IO.Directory.Exists(dataDir);
if (!IsExists)
System.IO.Directory.CreateDirectory(dataDir);
// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Obtaining the reference of the worksheet
Worksheet worksheet = workbook.Worksheets[0];
// Accessing the "A1" cell from the worksheet
Aspose.Cells.Cell cell = worksheet.Cells["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();
// Shrinking the text to fit according to the dimensions of the cell
style.ShrinkToFit = true;
cell.SetStyle(style);
// Saving the Excel file
workbook.Save(dataDir + "book1.out.xls", SaveFormat.Excel97To2003);
دمج Cells

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

  • الصف الأول: الصف الأول من حيث بدء الدمج.
  • العمود الأول: العمود الأول من حيث بدء الدمج.
  • عدد الصفوف: عدد الصفوف المراد دمجها.
  • عدد الأعمدة: عدد الأعمدة المراد دمجها.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Create directory if it is not already present.
bool IsExists = System.IO.Directory.Exists(dataDir);
if (!IsExists)
System.IO.Directory.CreateDirectory(dataDir);
// Create a Workbook.
Workbook wbk = new Workbook();
// Create a Worksheet and get the first sheet.
Worksheet worksheet = wbk.Worksheets[0];
// Create a Cells object ot fetch all the cells.
Cells cells = worksheet.Cells;
// Merge some Cells (C6:E7) into a single C6 Cell.
cells.Merge(5, 2, 2, 3);
// Input data into C6 Cell.
worksheet.Cells[5, 2].PutValue("This is my value");
// Create a Style object to fetch the Style of C6 Cell.
Style style = worksheet.Cells[5, 2].GetStyle();
// Create a Font object
Font font = style.Font;
// Set the name.
font.Name = "Times New Roman";
// Set the font size.
font.Size = 18;
// Set the font color
font.Color = System.Drawing.Color.Blue;
// Bold the text
font.IsBold = true;
// Make it italic
font.IsItalic = true;
// Set the backgrond color of C6 Cell to Red
style.ForegroundColor = System.Drawing.Color.Red;
style.Pattern = BackgroundType.Solid;
// Apply the Style to C6 Cell.
cells[5, 2].SetStyle(style);
// Save the Workbook.
wbk.Save(dataDir + "mergingcells.out.xls");

الطريقة الأخرى هي استدعاءCells المجموعةCreateRange طريقة لإنشاء نطاق من الخلايا المراد دمجها. الCreateRange تأخذ الطريقة نفس مجموعة المعلمات مثل تلك الخاصة بـدمج الطريقة التي تمت مناقشتها أعلاه وإرجاع أنطاق موضوع. النطاق يوفر الكائن أيضًا ملفدمج الأسلوب الذي يدمج النطاق المحدد فينطاقموضوع.

اتجاه النص

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

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

أنواع اتجاه النص وصف
سياق الكلام ترتيب القراءة المتوافق مع لغة أول حرف تم إدخاله
من اليسار إلى اليمين ترتيب القراءة من اليسار إلى اليمين
من اليمين الى اليسار ترتيب القراءة من اليمين إلى اليسار
// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Obtaining the reference of first worksheet
Worksheet worksheet = workbook.Worksheets[0];
// Accessing the "A1" cell from the worksheet
Cell cell = worksheet.Cells["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.TextDirection = (TextDirectionType.LeftToRight);
cell.SetStyle(style);
// Saving the Excel file
workbook.Save("book1.xlsx");

موضوعات مسبقة