【发布时间】:2014-10-27 04:17:42
【问题描述】:
我看到有人问过类似的问题,但我发现没有一个问题可以解决我的具体情况。
我在 Visual Studio 2010 中有一个 Excel 2007 COM 插件,用 C# 编写。当我将活动工作簿加载到功能区代码中的工作簿对象中时,它工作正常。当我在 Windows 窗体中执行此操作时,它每次都从活动工作簿返回 null。
以下是我的 using 语句和错误不断发生的代码的 sn-p。
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using Office = Microsoft.Office.Core;
using System.Windows.Forms;
using Excel = Microsoft.Office.Interop.Excel;
using System.Drawing;
---------------------------------------------------
Excel.Application xlApp;
xlApp = (Excel.Application)Marshal.GetActiveObject("Excel.Application");
Excel.Workbook xlWkbk = (Excel.Workbook)xlApp.ActiveWorkbook;
Excel.Worksheet xlWksht = (Excel.Worksheet)xlWkbk.ActiveSheet;
任何帮助将不胜感激!
【问题讨论】:
-
您从未打开/创建过新工作簿,因此您创建了一个没有打开任何内容的 Excel shell,我想......
-
约翰,感谢您的回复!所以,我不想创建或打开任何工作簿。我只想要活动工作簿。