從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