Set the field "Last Modified By" in the office DOCX file metadata -Apache POI 3.9-

StackOverflow https://stackoverflow.com/questions/18451157

  •  26-06-2022
  •  | 
  •  

Domanda

With POIXMLProperties.getCoreProperties() and POIXMLProperties.getExtendedProperties()

I can set all the metadata values ​​except "Last Modified By", Is there any way to set it?

Thanks for advance.

È stato utile?

Soluzione

I'm using POI 3.10-beta1 and it works for me, i.e. you can set it directly in the PackageProperties:

import java.util.Date;
import org.apache.poi.openxml4j.opc.*;
import org.apache.poi.openxml4j.util.Nullable;

public class LastModifiedBy {
    public static void main(String[] args) throws Exception {
        OPCPackage opc = OPCPackage.open("lastmodifed.docx");
        PackageProperties pp = opc.getPackageProperties();
        Nullable<String> foo = pp.getLastModifiedByProperty();
        System.out.println(foo.hasValue()?foo.getValue():"empty");
        pp.setLastModifiedByProperty("user"+System.currentTimeMillis());
        pp.setModifiedProperty(new Nullable<Date>(new Date()));
        opc.close();
    }
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top