2013-07-10 56 views
0

我的目標是顯示Excel文件的日期。 但是: 如果我從互聯網下載文件,automaitclly將創建日期和修改日期設置爲當前時間和日期。 我查看了文件的屬性,發現在「詳細信息」一節中,在個人信息下有一個名爲「源」的部分,在那裏,它具有一個名爲 '內容創建'的屬性與原始日期文件。獲取Excel文件的內容創建日期

有沒有辦法讓它成爲一個字符串?

謝謝。

回答

0

您可以使用Microsoft DSO OLE文檔屬性閱讀器來獲得這個。

DSOFile.OleDocumentPropertiesClass oleDocumentPropertiesClass = new DSOFile.OleDocumentPropertiesClass(); 
oleDocumentPropertiesClass.Open("C:\\My Documents\\MyExcelFile.xls"); 
MessageBox.Show(oleDocumentPropertiesClass.SummaryProperties.DateCreated.ToString()); 

的DSO文件可以從http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/Q224/3/51.asp

+0

這對我有效。 請注意,您必須添加DSO.dll並將其引用到您的項目中。另請注意,此值可以爲空。 請務必記住這一點。 謝謝jac @jac – subirshan

1

在VBA中你可以使用ThisWorkbook.BuiltinDocumentProperties("Creation Date")這樣的特性:

Sub GetCreationDate() 
MsgBox ThisWorkbook.BuiltinDocumentProperties("Creation Date") 
End Sub 

我沒有使用C#與Excel雖但MSDN文檔有一個例子:Workbook.BuiltinDocumentProperties Property (MSDN)

+0

創建日期 - 日期是小寫 – Sorceri

+0

不是根據我鏈接的MSDN頁面。 – jpw

+0

Dim bidp對於每個bidp在ThisWorkbook.BuiltinDocumentProperties如果bidp.Name =「創建日期」然後MsgBox CStr(bidp.Value)如果下一步名稱值是但它看起來你也會工作,我的道歉。 – Sorceri

0

這裏下載是一個例子,JPW應該還是有他的回答標誌着點。不是這個。

Excel.Application eApp = null; 
      Excel.Workbook eBook = null; 
       eApp = new Excel.Application(); 

       eBook = eApp.Workbooks.Open(pathToFile, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); 

       var docProp = eBook.BuiltinDocumentProperties("Creation Date"); 
       System.DateTime dt = docProp.Value; 
       MessageBox.Show(dt.ToLongTimeString());