获取C#中打开的Excel文档列表? [英] get list of opened Excel documents in C#?
本文介绍了获取C#中打开的Excel文档列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这里我成功打开Word文档打开文件列表
Here i get Word document opened file list successfully
try
{
Microsoft.Office.Interop.Word.Application WordObj;
WordObj = (Microsoft.Office.Interop.Word.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application");
x = "";
for (int i = 0; i < WordObj.Windows.Count; i++)
{
object idx = i + 1;
Microsoft.Office.Interop.Word.Window WinObj = WordObj.Windows.get_Item(ref idx);
// doc_list.Add(WinObj.Document.FullName);
x = x + "," + WinObj.Document.FullName;
//x = WinObj.Document.FullName;
}
}
catch (Exception ex)
{
// No documents opened
}
和我想要的Excel文件列表一样...
As same as i wantt to get Excel files list...
try
{
Microsoft.Office.Interop.Excel.Application ExcelObj;
ExcelObj = (Microsoft.Office.Interop.Excel.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
//excel = (Excel.Application)Marshal.GetActiveObject("Excel.Application");
x = "";
for (int i = 0; i < ExcelObj.Windows.Count; i++)
{
object idx = i + 1;
Microsoft.Office.Interop.Excel.Window WinObj = ExcelObj.Windows.get_Item(idx);
doc_list.Add(WinObj.Document.FullName);
x = x + "," + WinObj.Activate.
//x = WinObj.Document.FullName;
}
}
catch (Exception ex)
{
}
我有问题
x = x +,+ WinObj.Document.FullName;
它成功显示已打开的文件全名..
但
Excel文件没有...
x = x +,+ WinObj.Document.FullName;
WinObj.Document ..如何获取文档文件名.. 。
I have an proble with
x = x + "," + WinObj.Document.FullName;
It shows the Opened document Full name successfully..
But
Excel file not getting..
x = x + "," + WinObj.Document.FullName;
WinObj.Document ..How can i get Document file name...
推荐答案
请尝试使用Application.Workbooks
集合:
Try using theApplication.Workbooks
collection instead:
var excelApplication = (Excel.Application)Marshal.GetActiveObject("Excel.Application");
for (int i = 0; i < excelApplication.Workbooks.Count; i++)
{
Excel.Workbook workbook = excelApplication.Workbooks[i];
doc_list.Add(workbook.FullName);
}
这篇关于获取C#中打开的Excel文档列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文