简体   繁体   中英

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

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?

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

This should work (not tested) :

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

See : POI API docs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM