正如标题所说,我尝试将剪贴板中的内容粘贴到Excel中。C#将剪贴板内容粘贴到Excel工作表
我下面的代码:
Clipboard.SetText(html);
sheet.Range("A1").Value = Clipboard.GetText();
实际上,可变HTML包含HTML代码的文件,当我这样做,我其实如果我只粘贴HTML内容纳入范围,但是,打开Excel并手动完成,选择性粘贴...我可以粘贴HTML代码,但它将代码转换为真正的表格而不是HTML代码,这是我想要的真实结果,而无需手动完成。
Excel.Range.Copy() paste with Clipboard.GetText()
另一种方法是:
foreach (Excel.Worksheet sheet in workbook.Sheets)
{
foreach (Excel.Shape shape in sheet.Shapes)
{
Clipboard.SetText(html);
//doesn't work:
sheet.Range("A1").Value = sheet.PasteSpecial(Clipboard.GetText());
sheet.PasteSpecial(Clipboard.GetText()); //throws error
}
}
但这种方式并没有工作过。我可以使用html - >图像来粘贴图像,但实际值应该可以访问,而不是图片。
希望有人可以澄清如何解决它。
谢谢。
可能重复? http://stackoverflow.com/questions/10147152/excel-paste-special-and-add-operation – Nahum 2013-03-27 08:50:08