在 C# 中获取打开的 Excel 文档列表?
get list of opened Excel documents in C#?
这里我得到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 文件名文档没有属性...我怎样才能得到文件已满名称与单词相同..
我在 Whosebug 上找到了这个
你可以试试
//Excel Application Object
Microsoft.Office.Interop.Excel.Application oExcelApp;
this.Activate ( );
//Get reference to Excel.Application from the ROT.
oExcelApp = ( Microsoft.Office.Interop.Excel.Application ) System.Runtime.InteropServices.Marshal.GetActiveObject ( "Excel.Application" );
//Display the name of the object.
MessageBox.Show ( oExcelApp.ActiveWorkbook.FullName );
//Release the reference.
oExcelApp = null;
我在这里找到了这个
How to get the current open documents in Excel using C#?
这里
这里我得到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 文件名文档没有属性...我怎样才能得到文件已满名称与单词相同..
我在 Whosebug 上找到了这个
你可以试试
//Excel Application Object
Microsoft.Office.Interop.Excel.Application oExcelApp;
this.Activate ( );
//Get reference to Excel.Application from the ROT.
oExcelApp = ( Microsoft.Office.Interop.Excel.Application ) System.Runtime.InteropServices.Marshal.GetActiveObject ( "Excel.Application" );
//Display the name of the object.
MessageBox.Show ( oExcelApp.ActiveWorkbook.FullName );
//Release the reference.
oExcelApp = null;
我在这里找到了这个 How to get the current open documents in Excel using C#?
这里