WPF DataGrid HTML clipboard data faulty
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 76/100
Research direction
Start in Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridClipboardHelper.cs, especially lines 86-102, and reproduce copying selected DataGrid content before pasting into Excel. Verify the HTML clipboard offsets against the generated content; done means Excel and other applications accept the copied HTML without requiring a workaround.
Written by the indexing model from the issue text.
Description
Description
The HTML fragment DataGrid puts into the clipboard is not accepted by other applications.
It appears that the fragment's offsets (StartHTML/EndHTML/StartFragment/EndFragment) do not match the content.
Reproduction Steps
Select all data in a DataGrid, copy and then paste to Excel.
Expected behavior
Excel (or other application) correctly accepts HTML data from DatGrid in clipboard.
Actual behavior
Application cannot interpret and paste HTML data copied from DataGrid but display error.
Regression?
Error was introduced with #8519.
Known Workarounds
- Derive DataGrid subclass and override OnExecutedCopy:
protected override void OnExecutedCopy(ExecutedRoutedEventArgs args)
{
base.OnExecutedCopy(args);
String htmlData = Clipboard.GetData(DataFormats.Html) as String;
htmlData = htmlData.Replace("\r\n\r\n", "\r\n");
Clipboard.SetData(DataFormats.Html, htmlData);
}
2. Manually select csv or other format when pasting data copied from DataGrid in other applications.
### Impact
High impact at my company's backoffice which uses copy/paste to Excel intensely. On a more general scale, probably low.
### Configuration
.Net 9 Win11
### Other information
The problem with the wrong offsets is a result of double CR/LFs between the header items in Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridClipboardHelper.cs (lines 86-102) - remove those and everything works as before.
- Dominant language
- C#
- Stars
- 7.7k
- Forks
- 1.3k
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 75
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dotnet/wpf
-
Accessibility
Difficulty 1/5 Under an hour Newbie friendliness 88/100
-
area-Build Community Discussion Discuss In WPF Team Triage
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Good First Issue PR Proposed
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
:construction: work in progress
Difficulty 1/5 Under an hour Newbie friendliness 78/100
-
```Rect.Contains(double x, double y)``` returns ```true``` for points on both right and bottom edges Open:mailbox_with_no_mail: waiting-author-feedback
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Similar issues
-
type/automation type/tech-debt
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
t/bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
ci-failure-cause test-failure
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
area:auth FE mvp P3
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
klasolsson81/jobbliggaren#1788 ·