Specificare avviso di ordinamento durante l ordinamento dei dati
Possibili Scenari di Utilizzo
Considera questi dati testuali cioè {11, 111, 22}. Questi dati testuali sono ordinati perché, in termini di testo, 111 viene prima di 22. Ma, se vuoi ordinare questi dati non come testo ma come numeri, allora saranno {11, 22, 111} perché numericamente 111 viene dopo 22. Aspose.Cells for Node.js via C++ fornisce la proprietà {0} per gestire questo problema. Imposta questa proprietà true e i tuoi dati testuali saranno ordinati come dati numerici. La schermata seguente mostra l’avvertimento di ordinamento mostrato da Microsoft Excel quando i dati testuali che assomigliano a dati numerici vengono ordinati.
Codice di Esempio
Il seguente codice di esempio illustra l’uso della proprietà DataSorter.setSortAsNumber come spiegato in precedenza. Si prega di controllare il file di esempio Excel e l' output Excel file per ulteriori informazioni.
//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"); |