Cant paste the previously copied cells after clearing the sheet
Thank you for providing the demo. Based on the information provided, we understand that you are experiencing an issue with pasting previously copied cells after clearing the sheet. We have prepared a video demonstrating this issue.
Malini Selvarasu
Attachment: SfSpreadSheet___Issue_b8d7f241.zip
Yes,I forgot to add the video to the attachments.
Thank you for confirming this issue. We are currently analyzing the scenario you reported and require additional time to validate it. We will provide an update on or before October 30, 2024.
Malini Selvarasu
We have reviewed the reported scenario and confirmed that it is the default behavior of the spreadsheet. When clearing the sheet using the ActiveSheet.Clear() method, the contents are removed, which also eliminates any relevant context for pasting previously copied data. As a result, the copied data is not retained after the sheet is cleared.
No, what I want is to have the copied data directly stored in the clipboard, so that even if the data is cleared, it can still be pasted elsewhere.
Malini Selvarasu
As we mentioned earlier, when pasting data using Ctrl+V or the context menu options, the data is not pasted, which is the default behavior of the spreadsheet. We have verified the same behavior in Excel, and it behaves in the same way. We have attached a video demonstrating this behavior.
Attachment: Excel__Video_Reference_81aa1670.zip
Hi crosslife,
We regret the inconvenience. We are unable to include the fix for this issue, "Pasting from the Clipboard did not work after clearing the Worksheet" in our NuGet package released today as promised.
We would like to inform you that when data is copied from the spreadsheet, the copied range is stored. During pasting, this range is moved to the targeted range (i.e., the pasted range). However, when the active sheet is cleared, the copied range's text is also cleared, leaving it empty. As a result, pasting from the clipboard history (Windows + V) does not work after clearing the worksheet. We will address this issue in the first weekly NuGet release following the 2024 Volume 4 main release.
We will let you know once it is released. We appreciate your patience until then.
Thank you for your understanding and cooperation.
I am developing an application where cells only contain plain text. I want to achieve the following: after copying, all cell texts should be stored in the clipboard using a specific data structure, so that even after the ActiveSheet is cleared, the content can still be pasted anywhere, including in another process.
As I mentioned in
If there's a way to disable the default copy-paste logic of the Spreadsheet and implement my own by listening to keyboard events and menu responses, that would also work.
We apologize for the inconvenience. Unfortunately, we were unable to include the fix for the issue "Pasting from the Clipboard did not work after clearing the Worksheet" in our NuGet package released today, as promised.
Malini Selvarasu
We apologize for the inconvenience. Unfortunately, we were unable to include the fix for the issue, "Pasting from the Clipboard does not work after clearing the Worksheet," in today's NuGet package release as promised. We are still facing challenges in aligning the behavior with Excel after clearing the sheet and attempting to paste.
Hi crosslife,
We have investigated the reported issue on our end. In the Spreadsheet, we handle the sheet and grid separately. For reference, any updates made to a sheet are internally processed in the grid, and similarly, any actions performed on the grid are processed in the sheet.
In this case, when clearing data from the active sheet, the ranges and their values are cleared. However, we do not receive any notifications from the sheet, which prevents us from clearing the grid-related implementations or APIs, ultimately causing the issue. To address this, we have customized the Spreadsheet to handle this scenario effectively. Refer to the below code snippet,
C# Code Snippet related to CustomCopyPaste:
/// <summary> /// Provides custom copy-paste functionality for the spreadsheet. /// </summary> public class CustomCopyPaste : SpreadsheetCopyPaste { /// <summary> /// Gets or sets the associated SfSpreadsheet instance. /// </summary> public SfSpreadsheet SpreadSheet { get; set; }
/// <summary> /// Initializes a new instance of the EnhancedCopyPaste class. /// </summary> /// <param name="spreadsheet">The associated SfSpreadsheet instance.</param> public CustomCopyPaste(SfSpreadsheet spreadsheet) : base() { SpreadSheet = spreadsheet; }
/// <summary> /// Clears the copied text in clipboard and resets copy-paste related properties. /// </summary> public void Clear() { var sourceRangeText = GetPrivateProperty("SourceRangeText"); if (!string.IsNullOrEmpty(sourceRangeText)) { Clipboard.Clear(); SetPrivateProperty("SourceRangeText", null); } SourceRange = null; SourceWorkbookRange = null; ClipboardText = null; SpreadSheet.GetType().GetMethod("RefreshCurrentCell", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(SpreadSheet, null); }
/// <summary> /// Sets the value of a private property in the base class. /// </summary> private void SetPrivateProperty(string propertyName, object value) { this.GetType().BaseType.GetProperty(propertyName, BindingFlags.Instance | BindingFlags.NonPublic) .SetValue(this, value); }
/// <summary> /// Get the value of a private property in the base class. /// </summary> private string GetPrivateProperty(string propertyName) { return (string)this.GetType().BaseType.GetProperty(propertyName, BindingFlags.Instance | BindingFlags.NonPublic) .GetValue(this); } |
C# Code Snippet related to Initialization of CustomCopyPaste and clear method:
public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); // Initialize custom copy-paste functionality spreadsheet.CopyPaste = new CustomCopyPaste(spreadsheet); }
/// <summary> /// Handles the Clear button click event. /// Clears the active worksheet and resets the copy-paste state. /// </summary> private void ClearButton_Click(object sender, RoutedEventArgs e) { var worksheet = spreadsheet.ActiveSheet; worksheet.Clear(); // Clear the copy-paste properties (spreadsheet.CopyPaste as CustomCopyPaste)?.Clear(); spreadsheet.ActiveGrid.InvalidateCells(); //When clicking the button, the focus shifts to the button, //causing the focus to leave the spreadsheet. As a result, the Win + V key does not function as expected. //To resolve this issue, set the focus back to the active grid of the spreadsheet. spreadsheet.ActiveGrid.Focus(); } |
Find the modified sample demo in the attachment.
Attachment: Modified_Sample_4_71ff1e28.zip
- 13 Replies
- 3 Participants
-
CR crosslife
- Oct 23, 2024 03:58 AM UTC
- Jan 7, 2025 02:07 PM UTC