[英]Copy Dictionary<String, String> to clipboard for Excel
I am trying to write a tool which will compare two string tables and find values which are in one but not the other. 我正在尝试编写一种工具,该工具将比较两个字符串表并查找其中一个而不是另一个中的值。 I have got the app so that it is getting all these values correctly and I store them in a
Dictionary<string, string>
and use that to display it on a GridView in my XAML. 我有此应用程序,因此它可以正确获取所有这些值,并将它们存储在
Dictionary<string, string>
并使用它在我的XAML中的GridView上显示它。
I then found out that you have to manually add the copy code to the GridView so I thought I would just have a button to copy the entire contents of the dictionary, but now I am having a problem that when I try to copy it into excel it only produces one column of values and I need the key to be one column and the value to be another. 然后,我发现您必须手动将复制代码添加到GridView中,所以我想我只需要一个按钮即可复制字典的全部内容,但是现在我遇到了一个问题,当我尝试将其复制到excel中时它只产生一列值,而我需要将键设为一列,并将值设为另一列。
Here is my copy code so far: 到目前为止,这是我的复制代码:
if (ToTranslate.Count != 0)
{
var sb = new StringBuilder();
foreach (var item in ToTranslate)
{
sb.Append(item.Key + ", ");
sb.AppendLine(item.Value);
}
System.Windows.Clipboard.SetData(DataFormats.Text, sb.ToString());
}
I have tried lots of other things such as item.string which the puts them in square brackets and still doesn't work. 我尝试了很多其他事情,例如item.string,将它们放在方括号中仍然无法正常工作。 I have also tried trimming the square brackets but this still doesn't work.
我也尝试过修剪方括号,但这仍然行不通。
I would have thought that it would have picked up the comma as a seperator like it does when you open up a csv but it doesn't. 我本以为它会像分隔符一样用逗号分隔,就像打开csv时一样。
I don't know if this will help but this is my xaml 我不知道这是否有帮助,但这是我的xaml
<ListView ItemsSource="{Binding Results}">
<ListView.View>
<GridView>
<GridViewColumn Header="Name" Width="100" DisplayMemberBinding="{Binding Key}" />
<GridViewColumn Header="Text" Width="Auto" DisplayMemberBinding="{Binding Value}" />
</GridView>
</ListView.View>
</ListView>
Excel likes the tab character as separator. Excel喜欢使用制表符作为分隔符。 To import CSV you need the import assistent of Excel and that thing only opens in case you open a file that contains the CSV data.
要导入CSV,您需要Excel的导入助手,并且只有在您打开包含CSV数据的文件时,该东西才会打开。
Using the tab character is working well how ever. 使用制表符非常有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.