【发布时间】:2015-02-05 19:23:20
【问题描述】:
这里我成功获取Word文档打开文件列表..
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 文件列表一样...
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);
//Here is the problem ,How can i get FullName of opened excel file
// x = x + "," + WinObj.Activate.
// x = WinObj.Document.FullName;
}
}
catch (Exception ex)
{
}
Excel 文件没有得到..这条线.. 在每个word文档中都很好..with WinObj.Document.Fullname 但是 在 Excel x = x + "," + WinObj.Document.FullName; 没有 Excel 文件名文档的属性...我怎样才能获得与 word 相同的文件全名..
【问题讨论】:
-
每次空抓异常,小猫就会死去。
-
请注意,Excel 2010 到 2013(ish)之间的模型发生了变化——您的目标是什么?
-
我正在使用 Excel 2010..我想显示打开的 excel 打开的文档文件名..有没有可能找到这种方式..?