Step 1: I entered 11, 12, 13, and 14 in different cells.
Step 2: I applied red color to some cells.
Step 3: I applied yellow color to other cells.
Step 4: When performing undo (Ctrl + Z), the colors are removed correctly, but the text values (11, 12, 13, 14) remain and are not undone.
I have attached the reference GIF file**
redo and undo.gif (1.8 MB)
@sarathepiq
Cause
The issue you’re experiencing with the undo and redo actions in Aspose.Cells stems from the way the undo stack is managed. When you apply formatting changes (like cell colors), the text values in the cells are not being tracked as part of the undo stack, which is why they remain unchanged after an undo operation.
Solution
To ensure that both text values and formatting changes are properly managed in the undo stack, you need to explicitly handle the state of the cell values when applying formatting. This can be accomplished by saving the current state of the cell values before making any formatting changes.
Code
Here’s a sample code snippet that demonstrates how to manage the undo stack for both text values and formatting:
// Assuming 'workbook' is your Workbook object and 'worksheet' is your Worksheet object
var cells = worksheet.Cells;
// Store the original values before applying formatting
var originalValues = new Dictionary<int, string>();
for (int i = 0; i <= cells.MaxDataRow; i++)
{
for (int j = 0; j <= cells.MaxDataColumn; j++)
{
originalValues.Add(i * cells.MaxDataColumn + j, cells[i, j].Value.ToString());
}
}
// Apply formatting
cells[0, 0].SetStyle(new Style { Color = Color.Red });
cells[1, 0].SetStyle(new Style { Color = Color.Yellow });
// When undoing, restore the original values
foreach (var entry in originalValues)
{
int row = entry.Key / cells.MaxDataColumn;
int column = entry.Key % cells.MaxDataColumn;
cells[row, column].PutValue(entry.Value);
}
Next Steps
- Implement the above code in your application where you handle cell formatting.
- Test the undo functionality to ensure that both text values and formatting changes are reverted correctly.
- If the issue persists, check for any updates or patches for Aspose.Cells that might address this behavior.
Please proceed with these steps, and let me know if you need further assistance!
@sarathepiq
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): CELLSGRIDJS-1770
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
hi @simon.zhao , just want to check from your side regarding the resolution of Issue ID(s): CELLSGRIDJS-1770.
Any tentative timeline or release which is planned for?
This functionality is needed for our Aspose cells editor work
@Ghani0303
This feature is quite complex. We aim to implement it before the end of the year.