问题
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