Try the following:
- Create a new xlsx file by Excel.
- Select a row and set this row with a data validation(any validation).
- Save file and close Excel, open this file with Aspose.Cells.
- Create a new worksheet, and looping copy some column(Worksheet.Cells.CopyColumn) in reversed.
- Check the changes of Worksheet.Validations of new worksheet in this step.
- Save the file and try open it in Excel, you will got a error that tell you this file has been broken.
Core example code:
var wb = new Workbook(xlsxFilePath);
var sheet = wb.Worksheets[0];
Print(sheet.Validations[0]);
var newSheet = wb.Worksheets.Add("Reorder");
for (var i = 0; i < 5; i++)
{
newSheet.Cells.CopyColumn(sheet.Cells, 5 - i, i);
Console.WriteLine("Copied validation count:" + newSheet.Validations.Count);
Console.Write("Copied validation area:");
Print(newSheet.Validations[newSheet.Validations.Count - 1].Areas);
}
wb.Save(wb.FileName + ".edited.xlsx");
According to the exception information, it is speculated that have not checked the sheet boundary when copy validation, create a CellArea with out of sheet boundary.
You can also try test “Cells.CopyColumns”, “Cells.CopyRow”, “Cells.CopyRows”.
BTW: If not reorder when copy, file will not broken. But reopen the output file and check the validation of new sheet, you will found that the same validation with overlapping range not merged.
var wb = new Workbook(xlsxFilePath + ".edit.xlsx");
var newSheet = wb.Worksheets[1];
foreach(Validation va in newSheet.Validations)
{
Console.Write("Copied validation area:");
Print(va.Areas);
}
wb.Dispose();