我需要从一系列单元格中删除公式,以便仅保留值。
我正在使用Excel.Interop
我已经记录了VBA宏(只需复制所有内容并粘贴特殊值),并在C#
中使用以下代码进行了相同的操作:
xlWorkSheet.Activate();
xlWorkSheet.Range["A:Z"].Copy();
xlWorkSheet.UsedRange.ClearContents();
xlWorkSheet.Range["A:Z"].Select();
xlWorkSheet.Range["A:Z"].PasteSpecial(
Excel.XlPasteType.xlPasteValues,
Excel.XlPasteSpecialOperation.xlPasteSpecialOperationNone,
System.Type.Missing, System.Type.Missing);
但是,我收到以下错误:
System.Runtime.InteropServices.COMException:'Range类的PasteSpecial方法失败'
找出:
xlWorkSheet.Activate();
xlWorkSheet.Range["A:Z"].Select();
xlWorkSheet.UsedRange.Copy();
xlWorkSheet.Range["A:Z"].PasteSpecial(Excel.XlPasteType.xlPasteValues, Excel.XlPasteSpecialOperation.xlPasteSpecialOperationNone, System.Type.Missing, System.Type.Missing);