تحديد تحذير الفرز أثناء فرز البيانات
سيناريوهات الاستخدام المحتملة
يرجى مراعاة هذه البيانات النصية أي {11، 111، 22}. يتم ترتيب هذه البيانات النصية لأن 111 تأتي قبل 22 من حيث النص. ولكن، إذا كنت تريد فرز هذه البيانات كأرقام وليس كنص، فستصبح {11، 22، 111} لأن 111 تأتي بعد 22 رقميًا. توفر Aspose.Cells for Node.js via C++ الخاصية {0} للتعامل مع هذه المشكلة. يرجى تعيين هذه الخاصية على true، وسيتم فرز البيانات النصية كبيانات رقمية. تعرض لقطة الشاشة التالية التحذير من الفرز الذي يظهره Microsoft Excel عندما يتم فرز بيانات نصية تبدو كبيانات رقمية.
الكود المثالي
الكود المصدري العينة التالي يوضح استخدام الخاصية DataSorter.setSortAsNumber كما هو موضح سابقا. يرجى الاطلاع على ملف Excel عينة و ملف الإخراج Excel لمزيد من المساعدة.
//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
const AsposeCells = require("aspose.cells.node"); | |
//Create workbook. | |
var workbook = new AsposeCells.Workbook("sampleSortAsNumber.xlsx"); | |
//Access first worksheet. | |
var worksheet = workbook.getWorksheets().get(0); | |
//Create your cell area. | |
var ca = AsposeCells.CellArea.createCellArea("A1", "A20"); | |
//Create your sorter. | |
var sorter = workbook.getDataSorter(); | |
//Find the index, since we want to sort by column A, so we should know the index for sorter. | |
var idx = AsposeCells.CellsHelper.columnNameToIndex("A"); | |
//Add key in sorter, it will sort in Ascending order. | |
sorter.addKey(idx, AsposeCells.SortOrder.Ascending); | |
sorter.setSortAsNumber(true); | |
//Perform sort. | |
sorter.sort(worksheet.getCells(), ca); | |
//Save the output workbook. | |
workbook.save("outputSortAsNumber.xlsx"); |