データの並べ替え時の並べ替え警告の指定

考えられる使用シナリオ

このテキスト データ、つまり {11, 111, 22} を考慮してください。このテキスト データは、テキストに関しては 111 が 22 の前に来るため、並べ替えられます。ただし、このデータをテキストとしてではなく数値として並べ替えたい場合は、数値的には 111 が 22 の後に来るため、{11, 22, 111} になります。 Aspose.Cells提供DataSorter.SortAsNumberこの問題に対処するプロパティ。このプロパティを設定してください真実テキストデータは数値データとしてソートされます。次のスクリーンショットは、数値データのように見えるテキスト データが並べ替えられたときに、Microsoft Excel によって表示される並べ替えの警告を示しています。

todo:画像_代替_文章

サンプルコード

次のサンプル コードは、DataSorter.SortAsNumberプロパティは、前述のとおりです。チェックしてくださいサンプル Excel ファイル出力エクセルファイルさらにヘルプが必要です。

// 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.
Workbook workbook = new Workbook(dataDir + "sampleSortAsNumber.xlsx");
//Access first worksheet.
Worksheet worksheet = workbook.Worksheets[0];
//Create your cell area.
CellArea ca = CellArea.CreateCellArea("A1", "A20");
//Create your sorter.
DataSorter sorter = workbook.DataSorter;
//Find the index, since we want to sort by column A, so we should know the index for sorter.
int idx = CellsHelper.ColumnNameToIndex("A");
//Add key in sorter, it will sort in Ascending order.
sorter.AddKey(idx, SortOrder.Ascending);
sorter.SortAsNumber = true;
//Perform sort.
sorter.Sort(worksheet.Cells, ca);
//Save the output workbook.
workbook.Save(dataDir + "outputSortAsNumber.xlsx");