データをソートする際のソート警告の指定

可能な使用シナリオ

テキストデータ{11, 111, 22}を考慮してください。このテキストデータは、テキストにおいて111が22より前に来るためにソートされます。しかし、このデータをテキストではなく数字としてソートしたい場合、それは{11, 22, 111}になります。Aspose.Cellsはこの問題に対処するために{0}プロパティを提供します。このプロパティをtrueに設定すると、テキストデータが数値データとしてソートされます。次のスクリーンショットは、テキストデータが数字のように見える場合にMicrosoft Excelで表示されるソート警告を示しています。

todo:image_alt_text

サンプルコード

次のサンプルコードは、上記で説明したDataSorter.SortAsNumberプロパティの使用方法を説明しています。詳細については、サンプルExcelファイル(43352075.xlsx)とそれに対応する出力Excelファイル(43352076.xlsx)を確認してください。

// 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");