I am getting error while using the Excel Interops set_Value on a range. Any help/suggestion will be valuable.
This is the code which is failing.
using Excel = Microsoft.Office.Interop.Excel;
Excel.Application xlApp = new Excel.ApplicationClass();
Excel.WorkBook WB = xlApp.Workbooks.Add(Type.Missing);
Excel.WorkSheet WS = WB.Sheets[1] as Excel.WorkSheet;
object obj = (WS.get_Range("A1:D10") as Excel.Range).get_Value(Excel.XLRangeValueDataType.XLRangeValueMSPersistXML);
(WS.get_Range("A1:D10") as Excel.Range).set_Value(Excel.XLRangeValueDataType.XLRangeValueMSPersistXML,obj);
The code fails here. I am set开发者_如何学Cting the same object value which i am getting from excel range. The exception shown is System.NotImplementedException.
I am clueless at this point if it is the office interop doesn't support XLRangeValueMSPersistXML while setting the value back to the excel range.
When setting the value, it appears that you should leave off the RangeValueDataType setting. The following code does not cause the NotImplementedException to be thrown. (It also corrects some case problems that prevent your original sample from compiling, as well as tidying it up a bit.)
using Excel = Microsoft.Office.Interop.Excel;
Excel.Application xlApp = new Excel.ApplicationClass();
Excel.Workbook WB = xlApp.Workbooks.Add(Type.Missing);
Excel.Worksheet WS = WB.Sheets[1] as Excel.Worksheet;
Excel.Range r = WS.Range["A1:D10"];
var obj = r.Value[Excel.XlRangeValueDataType.xlRangeValueMSPersistXML];
r.Value = obj;
精彩评论