getting content-created-date of an excel file

2019-09-17 10:54发布

My goal is to display the date of an excel file. But : If I download the file from the internet , automaitclly the creation date and modify date are set to current time and date. I looked upon the file's properties , and found that in section 'Details' , under personal infomation , there is a section called 'Source' and there , it has a property called ' Content Created ' with the original date file.

Is there a way to get it to a string ??

Thanks .

3条回答
三岁会撩人
2楼-- · 2019-09-17 11:29

You can use the Microsoft DSO OLE Document Properties Reader to get this.

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

The DSO file can be downloaded from http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/Q224/3/51.asp

查看更多
迷人小祖宗
3楼-- · 2019-09-17 11:33

In VBA you can get the property using ThisWorkbook.BuiltinDocumentProperties("Creation Date") like this:

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

I haven't used c# with Excel though but the MSDN documentation has an example: Workbook.BuiltinDocumentProperties Property (MSDN)

查看更多
Melony?
4楼-- · 2019-09-17 11:39

Here is an example, JPW should still have his answer marked for the points. Not this one.

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());
查看更多
登录 后发表回答