如何使用C#和VSTO将特殊的未格式化纯文本粘贴到Excel中? [英] How can I paste special unformatted plain text into Excel using C# and VSTO?

查看:102
本文介绍了如何使用C#和VSTO将特殊的未格式化纯文本粘贴到Excel中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很难相信这个问题没有被提出或不可能解决,但这就是我在网络搜索中看到的.

It's hard to believe this question hasn't been asked or is not possible, but that's what I'm seeing from web searches.

我只想使用VSTO将未格式化的纯文本粘贴到活动单元格区域中.使用Range.PasteSpecial 仅提供粘贴值的选项(

All I would like to do is use VSTO to paste only the unformatted plain text into the active cell range. Using Range.PasteSpecial only gives the option to paste values (among others), but these include formatting. Is there really no option to paste unformatted text using PasteSpecial?

有人发现还有其他方法吗?在此应用程序中,不能使用宏.

Is there some other way that anyone has found to do this? Using macros are not an option in this application.

这正是我尝试过的:

((Excel.Range)Application.Selection).PasteSpecial(Excel.XlPasteType.xlPasteValues);

推荐答案

Excel.XlPasteType.xlPasteValues不会为我做这件事很奇怪,但是我最终只做了以下工作,

It's strange that Excel.XlPasteType.xlPasteValues wouldn't do it for me, but I ended up just doing the following, which works:

string textToPaste = (string)Clipboard.GetData("Text");
Clipboard.SetData("Text", textToPaste);
((Excel.Range)Application.Selection).PasteSpecial(Excel.XlPasteType.xlPasteValues);

希望对其他人有帮助!

这篇关于如何使用C#和VSTO将特殊的未格式化纯文本粘贴到Excel中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆