从Excel中读取计算值我们试图从其中包含加载公式的单元格中检索计算值。 示例加载项“myUtilityl.xla”在Excel中正常工作。它检索插件功能=ISOWEEKNUM(F9)
的值。但是我们无法使用C#编程方式检索该值。& Microsoft Object Library。加载项“myUtilityl.xla”连接到Excel。环境是VS2010使用AddIn公式和Microsoft Object Library
我在这里提供示例代码。
string path = @"C:\Test.xls";
Workbook theWorkbook;
Worksheet theWorksheet;
Range readRange;
Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
theWorkbook = app.Workbooks.Open(path);
Sheets theSheets = (Sheets)theWorkbook.Worksheets;
theWorksheet = (Worksheet)theWorkbook.Worksheets.get_Item("Sheet1");
readRange = theWorksheet.get_Range("B1");
MessageBox.Show(Convert.ToString(readRange.Value));
//theWorkbook.Save();
app.Workbooks.Close();
我是微软对象库的新手。任何帮助或线索都会非常有帮助。
你在消息框中得到什么? – 2012-01-03 16:26:57
获取垃圾值--------------------------- ---------------- ----------- -2146826259 --------------------------- OK ----- ---------------------- – 2012-01-04 09:30:17
是B1在myUtility.xla中调用UDF吗? – 2012-01-04 09:34:43