How can I paste special unformatted plain text into Excel using C# and VSTO?

牧云@^-^@ 提交于 2019-12-25 18:25:31

问题


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.

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.

Here is exactly what I tried:

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

回答1:


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);

Hopefully that helps someone else!



来源:https://stackoverflow.com/questions/13673373/how-can-i-paste-special-unformatted-plain-text-into-excel-using-c-sharp-and-vsto

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!