How to get the "last saved" attribute of an Office file in Java
I am trying to get the "last saved" attribute from an MS Office 2013 file (docx, xlsx, pptx ...). I am using Apache POI, but can only get 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 the "last saved" attribute?
+3
source to share
2 answers
Check out Apache POI OOXML Properties Extractor as a good source of inspiration for this kind of problem, we see what you need to do
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();
This will give you the last modified file, when and when it was created
+2
source to share
This should work (not tested):
OPCPackage pkg = OPCPackage.open(file);
pkg.getPackageProperties().getLastModifiedByProperty();
See: POI API Docs
0
source to share