فرز البيانات في العمود باستخدام قائمة الفرز المخصصة

سيناريوهات الاستخدام الممكنة

يمكنك فرز البيانات في العمود باستخدام قائمة مخصصة. يمكن القيام بذلك باستخدامDataSorter.AddKey (مفتاح int ، ترتيب SortOrder ، قائمة مخصصة للسلسلة)طريقة. ومع ذلك ، لا تعمل هذه الطريقة إلا إذا كانت العناصر الموجودة في القائمة المخصصة لا تحتوي على فواصل بداخلها. إذا كانت تحتوي على فواصل مثل “USA، US”، “China، CN” وما إلى ذلك ، فيجب عليك استخدام [** DataSorter.AddKey Method (Int32، SortOrder، String []) **)] (https: // reference. aspose.com/cells/net/aspose.cells.datasorter/addkey/methods/3) طريقة. هنا ، المعلمة الأخيرة ليست String ولكن مجموعة من السلاسل.

فرز البيانات في العمود باستخدام قائمة الفرز المخصصة

يوضح نموذج الكود التالي كيفية استخدام [** DataSorter.AddKey Method (Int32، SortOrder، String []) **)] (https://reference.aspose.com/cells/net/aspose.cells.datasorter/addkey / طرق / 3) طريقة لفرز البيانات باستخدام قائمة الفرز المخصصة. الرجاء مراجعة [نموذج ملف Excel] (50528327.xlsx) المستخدم في هذا الرمز و [ملف Excel الناتج] (50528328.xlsx) الذي تم إنشاؤه بواسطته. تُظهر لقطة الشاشة التالية تأثير الكود على نموذج ملف Excel عند التنفيذ.

ما يجب القيام به: image_بديل_نص

عينة من الرموز

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
//Load the source Excel file
Workbook wb = new Workbook(sourceDir + "sampleSortData_CustomSortList.xlsx");
//Access first worksheet
Worksheet ws = wb.Worksheets[0];
//Specify cell area - sort from A1 to A40
CellArea ca = CellArea.CreateCellArea("A1", "A40");
//Create Custom Sort list
string[] customSortList = new string[] { "USA,US", "Brazil,BR", "China,CN", "Russia,RU", "Canada,CA" };
//Add Key for Column A, Sort it in Ascending Order with Custom Sort List
wb.DataSorter.AddKey(0, SortOrder.Ascending, customSortList);
wb.DataSorter.Sort(ws.Cells, ca);
//Save the output Excel file
wb.Save(outputDir + "outputSortData_CustomSortList.xlsx");