解决方案出处:http://hi.baidu.com/%CB%E6%B7%E7%C6%AE1989/blog/item/48af7da07063c0914610645a.html
工具:http://files.cnblogs.com/yelaiju/vs2010CopyToWord.rar
现在安装SP1也可以修复这个bug
代码
try
{
// 取得剪贴板的内容:
IDataObject dataObject = Clipboard.GetDataObject();
// 确定粘贴的数据是否与指定的格式关联
if (dataObject.GetDataPresent(DataFormats.Rtf))
{ // 获取RTF数据
string rtf = dataObject.GetData(DataFormats.Rtf) as string;
// 以Regex.Replace去掉多余的字符(不管是否有,一律强制去除)
string fixedRtf = Regex.Replace(rtf, @" \\uinput2(?<uc>\\u-?\d*)\s.. ", (m) => { return m.Groups[ " uc "].Value + " ? "; });
// 另外新建一个DataObject对象
DataObject newDataObject = new DataObject();
// RTF格式用修改后的字符串,其余的还原
foreach ( string t in dataObject.GetFormats())
newDataObject.SetData(t, t == " Rich Text Format " ? fixedRtf : dataObject.GetData(t));
// 将修改后的内容写入剪贴板
Clipboard.SetDataObject(newDataObject, true);
}
}
catch (Exception ex)
{ MessageBox.Show(ex.ToString()); }
{
// 取得剪贴板的内容:
IDataObject dataObject = Clipboard.GetDataObject();
// 确定粘贴的数据是否与指定的格式关联
if (dataObject.GetDataPresent(DataFormats.Rtf))
{ // 获取RTF数据
string rtf = dataObject.GetData(DataFormats.Rtf) as string;
// 以Regex.Replace去掉多余的字符(不管是否有,一律强制去除)
string fixedRtf = Regex.Replace(rtf, @" \\uinput2(?<uc>\\u-?\d*)\s.. ", (m) => { return m.Groups[ " uc "].Value + " ? "; });
// 另外新建一个DataObject对象
DataObject newDataObject = new DataObject();
// RTF格式用修改后的字符串,其余的还原
foreach ( string t in dataObject.GetFormats())
newDataObject.SetData(t, t == " Rich Text Format " ? fixedRtf : dataObject.GetData(t));
// 将修改后的内容写入剪贴板
Clipboard.SetDataObject(newDataObject, true);
}
}
catch (Exception ex)
{ MessageBox.Show(ex.ToString()); }
本文转自火地晋博客园博客,原文链接:http://www.cnblogs.com/yelaiju/archive/2012/02/16/2354182.html,如需转载请自行联系原作者