Hi, I’m using the latest version Aspose.Cells for .Net (24.6.0) and when I use InsertCutCells to move worksheet columns, the conditional formatting of the worksheet becomes distorted. For reference, please see rows 42 to 53 in attached file ‘TestAsposeFormatting - Result’.
(Note that this issue seems to have been introduced in Aspose.Cells v 22.0 onwards as it works fine with v21.9)
The code I’m using is as follows:
public void GroupQuarters(Workbook wb)
{
// Move quarter groups
var worksheet = wb.Worksheets["Test"];
var rangeOriginalColumn = 7;
var insertColumn = 3;
while (rangeOriginalColumn <= 62)
{
Aspose.Cells.Range cutRange = GetRange(worksheet,
startRowIndex: 1,
startColumnIndex: rangeOriginalColumn,
endRowIndex: 91,
endColumnIndex: rangeOriginalColumn + 4 - 1);
var destRange = GetRange(worksheet, 1,insertColumn, 91, insertColumn);
Cut(sourceRange: cutRange,
destinationRange: destRange,
insertColumn);
insertColumn = insertColumn + 4;
rangeOriginalColumn = rangeOriginalColumn + 5;
}
var resultWorkbookPath = Path.Combine(Path.GetDirectoryName(wb.FileName), Path.GetFileNameWithoutExtension(wb.FileName)) + $" - Result.xlsx";
var fullResultFileName = Path.ChangeExtension(resultWorkbookPath, ".xlsx");
Directory.CreateDirectory(Path.GetDirectoryName(resultWorkbookPath));
wb.Save(fullResultFileName, SaveFormat.Xlsx);
}
public Aspose.Cells.Range GetRange(Aspose.Cells.Worksheet worksheet, int startRowIndex, int startColumnIndex, int endRowIndex, int endColumnIndex)
{
Aspose.Cells.Range range = worksheet.Cells.CreateRange(
firstRow: startRowIndex - 1,
firstColumn: startColumnIndex - 1,
totalRows: endRowIndex - startRowIndex + 1,
totalColumns: endColumnIndex - startColumnIndex + 1);
return range;
}
public void Cut(Aspose.Cells.Range sourceRange, Aspose.Cells.Range destinationRange, int insertColumn)
{
Aspose.Cells.Worksheet destinationWorksheet = destinationRange.Worksheet;
destinationWorksheet.Cells.InsertCutCells(
sourceRange,
0,
insertColumn - 1,
ShiftType.Right
);
}
Could you please help resolve this? Thanks in advance!
TestAsposeFormatting.zip (100.5 KB)