Tag: 编组

操作完成后释放Excel * 32进程

试图找出为什么我的EXCEL * 32过程仍然在使用,直到我的应用程序和excel文件都closures。 在创build之后,我必须丢失一些东西,就像这个代码之后,应用程序保存在EXCEL * 32资源中。 任何build议让它在出口操作后“放手”完成? 此外,我不想closures新创build的Excel工作表,我只想释放与我的实际.net应用程序相关的资源。 Application xls = new Application(); xls.SheetsInNewWorkbook = 1; // Create our new excel application and add our workbooks/worksheets Workbook Workbook = xls.Workbooks.Add(); Worksheet CrossoverPartsWorksheet = xls.Worksheets[1]; // Create our new excel application and add our workbooks/worksheets Workbook Workbook = xls.Workbooks.Add(); Worksheet CrossoverPartsWorksheet = xls.Worksheets[1]; ///////////////////////////////////////// // < […]

Excelselect更改事件触发两次C#

我尝试在Excel中调用selectionchange事件,但它触发两次。 我用编组连接到一个打开的Excel文件,所以代码如下 首先我发布Form1上的代码 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Reflection; using System.Diagnostics; using Excel = Microsoft.Office.Interop.Excel; namespace Excel_Sol_Taraf_Onaylama_V._00 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btn_Excele_Baglan_Classtan_Click(object sender, EventArgs e) { try { ExcelSinifveOlaylar myExcel = new […]

获得提升的excel过程

前几天,我不得不使用ProcessStartInfo以当前用户权限运行Excel,以便用户使用一些需要pipe理员权限或当前用户权限的插件。 new Process{ StartInfo = new ProcessStartInfo{ Verb = "runas", FileName = @"path/to/app.exe", Arguments = "-officeexcel", Domain = domain, UserName = login, Password = pa ss, UseShellExecute = false, } }.Start(); 因此,我不能再使用了: Marshal.GetActiveObject("Excel.Application") 得到excel实例。 所以我试图使用AccessibleObjectFromWindow()的后期绑定: int hwnd = (int)FindWindow("XLMAIN", null); if (hwnd != 0) { int hwndChild = 0; EnumChildCallback cb = new EnumChildCallback(EnumChildProc); EnumChildWindows(hwnd, […]

附加到现有的Excel实例

我试图确定是否打开一个特定的文件运行Excel的实例,如果这样附加到它,所以我可以控制该实例。 我已经搜遍了,而我所得到的大部分都来自这个问题。 它有一个对另一个网站的参考,但不幸的是它已经死了,所以我不能读它。 我的代码到目前为止是; //Is Excel open? if (Process.GetProcessesByName("EXCEL").Length != 0) { Process[] processes = Process.GetProcesses(); foreach (Process process in processes) { //Find the exact Excel instance if (process.ProcessName.ToString() == "EXCEL" && process.MainWindowTitle == ("Microsoft Excel – " + fileName)) { //Get the process ID of that instance int processID = (int)Process.GetProcessById(process.Id).MainWindowHandle; //Attach to the […]

用户打开Excel文件进​​行数据input后,在Windows中closuresExcel进程

程序打开Excels,读取工作表并填充每张工作表的数据。 对于打开的每个Excel来获取input数据,Windows进程列表中将会有一个Excel进程。 如果用户在运行期间随着时间的推移打开了许多Excels,将会有许多Excel进程在Windows中运行。 问题是,如果你去到一个文件夹,并试图打开一个以编程方式打开的Excel,它将只能被读取,因为在Windows中运行的Excel进程保留着它。 Windows中的每个Excel进程都需要终止才能释放每个以编程方式打开的Excal。 Imports Excel = Microsoft.Office.Interop.Excel ' Create new Application. Dim rXL As New Excel.Application Dim rWB As Excel.Workbook ' Dim rSheet As Excel.Worksheet Dim rRng As Excel.Range Dim buffmatrix(,) As Object rWB = rXL.Workbooks.Open(filename) Dim sheet As Excel.Worksheet For i = 1 To rWB.Sheets.Count To 1 Step -1 ' Get sheet. […]

即使VBA由Excel实例打开,也附加到现有的Excel实例

这是关于这个问题的select答案: 如何遍历Excel的实例c# 此代码非常适合于获取Excel的所有实例,除非这些实例中的一个已打开VBA编辑器。 当它试图findEXCEL7的类时代码会中断。 这是工作簿子窗口的类。 在debugging时,我确定在枚举子窗口时,EXCEL7子窗口不能被定位。 像VbaWindow类而不是显示。 我甚至试图得到这个窗口句柄的Excel.Window这个VBA窗口类,但它失败了。 我怎么能仍然得到的方法AccessibleObjectFromWindow引用Excel.Window,然后我可以用来引用应用程序。 这里是我修改的方法(我已经有Excel进程ID …所有其他声明被省略为了可读性): internal static Excel.Application GetExcelInstance(int procID) { EnumChildCallback cb; Process p = Process.GetProcessById(procID); if (p != null) { if ((int)p.MainWindowHandle > 0) { int childWindow = 0; cb = new EnumChildCallback(EnumChildProc); EnumChildWindows((int)p.MainWindowHandle, cb, ref childWindow); if (childWindow > 0) { const uint OBJID_NATIVEOM = 0xFFFFFFF0; […]

我怎样才能在XLOPER和VARIANT之间?

我正在处理与COM对象通信的Excel插件(XLL)。 所以,我必须在XLOPER和VARIANT之间进行编组。 我已经得到了大部分工作,但数组绝对是一个痛苦。 我需要支持1和2D数组。 我想有人已经不得不面对这个。 有没有一些库可以简化这个? 有处理VARIANT,SAFEARRAY和XLOPER(和XLOPER12)的好工具吗?

C#Excel互操作 – 如何testing互操作对象是否仍在工作并执行任务?

我正在循环浏览几个追踪的excel文件的目录,并尝试一次刷新一个excel文件。 我不断收到这个错误,指出刷新操作仍然在文件A上运行,例如,FileB正在尝试启动刷新操作。 循环是快速的,不知何故,我必须等待文件A上的先前刷新操作才能开始刷新文件B. 未处理的exception:System.Runtime.InteropServices.COMException:消息filter指示应用程序正忙。 (来自HRESULTexception:0x8001010A(RPC_E_SERVERCALL_RETRYLATER))在Microsoft.Office.Interop.Excel._Workbook.RefreshAll()在RefreshExcelFiles.Program.RefreshFile(string文件名) 这是我的代码。 在开始处理循环中的新文件之前,如何等待刷新操作完成? 或者,在开始新文件之前,等待wb对象的编组释放操作完成? using System; using System.Configuration; using System.IO; using System.Runtime.InteropServices; using Microsoft.Office.Interop.Excel; namespace RefreshExcelFiles { internal class Program { private static string _fileDirectory; private static Application _excelApp; private static void Main(string[] args) { _fileDirectory = ConfigurationManager.AppSettings["FileDirectory"]; _excelApp = new Application(); _excelApp.DisplayAlerts = false; Console.WriteLine("starting to refresh files"); int i […]