Hi,
Hi,
Thanks for your posting and using Aspose.Cells.
Please try the following fixed code, it should work fine at your end. Please use the MaxRow and MaxColumn properties to get the maximum row and columns.
C#
string fPath = @“F:\Shak-Data-RW\Downloads\test.xlsx”;
var workbook = new Workbook(fPath);
int index = workbook.Worksheets.Count;
for (int i = 0; i < index; i++)
{
Worksheet ws = workbook.Worksheets[i];
//Make column I as DateTime.
Style dateStyle = workbook.CreateStyle();
dateStyle.Number = 14;
StyleFlag flag = new StyleFlag();
flag.All = true;
ws.Cells.Columns[8].ApplyStyle(dateStyle, flag);
var cells = ws.Cells;
DataSorter sorter = workbook.DataSorter;
sorter.Order1 = Aspose.Cells.SortOrder.Descending;
sorter.Key1 = CellsHelper.ColumnNameToIndex(“I”);
var ca = new CellArea
{
StartRow = 1,
StartColumn = 3,
EndRow = cells.MaxRow - 1,
EndColumn = cells.MaxColumn
};
sorter.Sort(cells, ca);
for (int j = 0; j < ws.Cells.MaxRow; j++)
{
ws.AutoFitRow(j);
}
ws.AutoFitColumns();
}
workbook.Save(fPath + “.out.xlsx”);