获取所有打开的Excel文档 [英] Get all opened Excel-documents
问题描述
我需要使用自己的数据创建xls-file。但是文件可能已经被创建,并被用户打开。
I need create xls-file with own data. But file may already be created, and opened by user.
(1)如果文件不存在:
new ApplicationClass()
Workbooks.Add ()
SaveAs()...
(1) If file not exist: new ApplicationClass() Workbooks.Add() SaveAs()...
(2)如果文件存在且未打开:没问题 - goto(1)
(2) If file exist and not opened: not problem - goto (1)
(3)如果文件存在并且被用户打开:需要找到工作簿并修改工作表的数据。
(3) if the file exists and is opened by the user: need find it workbook and reform data of worksheet.
With 3)我有问题Marshal.GetActiveObject(Excel.Application)只找到活动的工作簿。
With (3) I have problem. Marshal.GetActiveObject("Excel.Application") finded only active workbook.
推荐答案
我知道迟到回答你,但可能对其他人有用。
I know is late to answer you, but may be useful to someone else.
Microsoft.Office.Interop.Excel.Application oExcelApp;
oExcelApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
foreach (Microsoft.Office.Interop.Excel.Workbook WB in oExcelApp.Workbooks) {
MessageBox.Show(WB.FullName);
}
oExcelApp = null;
这篇关于获取所有打开的Excel文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!