How to get “last saved by” Office file attribute in Java

我怕爱的太早我们不能终老 提交于 2019-12-12 14:55:43

问题


I am trying to get the "last saved by" attribute from MS Office 2013 file(docx, xlsx, pptx ...). I am using Apache POI, but I can get only the Author of the file with the following code:

OPCPackage pkg = OPCPackage.open(file);
POIXMLProperties props = new POIXMLProperties(pkg);
props.getCoreProperties().getCreator();

Is there a way to get "last saved by" attribute?


回答1:


Lookin at the Apache POI OOXML Properties Extractor as a good source of inspiration for this sort of problem, we see what you need to do is

OPCPackage pkg = OPCPackage.open(file);
POIXMLProperties props = new POIXMLProperties(pkg);
PackagePropertiesPart ppropsPart = props.getCoreProperties().getUnderlyingProperties();

Date created = ppropsPart.getCreatedProperty().getValue();
Date modified = ppropsPart.getModifiedProperty().getValue();

String lastModifiedBy = ppropsPart.getLastModifiedByProperty().getValue();

That'll give you who last modified the file, when, and when it was created




回答2:


This should work (not tested) :

OPCPackage pkg = OPCPackage.open(file);
pkg.getPackageProperties().getLastModifiedByProperty();

See : POI API docs



来源:https://stackoverflow.com/questions/27225499/how-to-get-last-saved-by-office-file-attribute-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!