الدمج والدمج Cells

مقدمة

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

دمج Cells بورقة عمل

دمج Cells في Microsoft Excel

تصف الخطوات التالية كيفية دمج الخلايا في ورقة العمل باستخدام MS Excel.

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

دمج Cells مع Aspose.Cells

الفئة Aspose.Cells.Cells لها بعض الطرق المفيدة للمهمة. على سبيل المثال ، تدمج الطريقة Merge () الخلايا في خلية واحدة ضمن نطاق محدد.

يوضح المثال التالي كيفية دمج الخلايا (C6: E7) في ورقة عمل.

// 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

باستخدام Microsoft إكسل

تصف الخطوات التالية كيفية تقسيم الخلايا المدمجة باستخدام Microsoft Excel.

  1. حدد الخلية المدمجة. عندما يتم الجمع بين الخلايا ،دمج ومركز علىتنسيق شريط الأدوات.
  2. انقردمج ومركز على التنسيق شريط الأدوات.

باستخدام Aspose.Cells

تحتوي الفئة Aspose.Cells.Cells على طريقة تسمى UnMerge () تقسم الخلايا إلى حالتها الأصلية. تقوم الطريقة بإلغاء دمج الخلايا باستخدام مرجع الخلية في نطاق الخلايا المدمجة.

يوضح المثال التالي كيفية تقسيم الخلايا المدمجة (C6). يستخدم المثال الملف الذي تم إنشاؤه في المثال السابق ويقسم الخلايا المدمجة.

// 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 a Workbook.
// Open the excel file.
Workbook wbk = new Aspose.Cells.Workbook(dataDir + "mergingcells.xls");
// 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;
// Unmerge the cells.
cells.UnMerge(5, 2, 2, 3);
// Save the file.
wbk.Save(dataDir + "unmergingcells.out.xls");

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