Results 1 to 5 of 5
  1. #1
    hoz
    hoz is offline Member
    Join Date
    Jan 2017
    Posts
    3
    Rep Power
    0

    Default How correct to set LastModifiedByProperty ?

    I wrote this method for set attribute LastModifiedByProperty in xlsx's file:
    Java Code:
        public static String getLastModifiedByUser(String user) throws IOException, OpenXML4JException, XmlException {
            OPCPackage pkg = OPCPackage.open(user);
            POIXMLProperties xmlProps = new POIXMLProperties(pkg);
            PackagePropertiesPart propertiesPart = xmlProps.getCoreProperties().getUnderlyingProperties();
            return propertiesPart.getLastModifiedByProperty().getValue();
        }
    I call this from Main class so:
    Java Code:
                try {
                    POIXMLProps.getLastModifiedByUser("hoz");
                } catch (Exception e) {
                    e.printStackTrace();
                }
    In journal intellj Idea I see that:
    Java Code:
    java.lang.IllegalStateException: Zip File is closed
    	at org.apache.poi.openxml4j.util.ZipFileZipEntrySource.getEntries(ZipFileZipEntrySource.java:45)
    	at org.apache.poi.openxml4j.opc.ZipPackage.getPartsImpl(ZipPackage.java:184)
    	at org.apache.poi.openxml4j.opc.OPCPackage.getParts(OPCPackage.java:684)
    	at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:227)
    	at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:187)
    	at xcell.POIXMLProps.getLastModifiedByUser(POIXMLProps.java:183)
    What is reason for those error?

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    19,493
    Rep Power
    29

    Default Re: How correct to set LastModifiedByProperty ?

    Does the OPCPackage class's open method have any documentation for that error?

    The getLastModifiedByUser method returns a value that is not saved by the caller on line 2.
    Last edited by Norm; 01-11-2017 at 08:11 PM.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    hoz
    hoz is offline Member
    Join Date
    Jan 2017
    Posts
    3
    Rep Power
    0

    Default Re: How correct to set LastModifiedByProperty ?

    Hm. It was my error, because in documentation this method named as getLastModifiedByUser() , but in IDE Intellij Idea this called not as in documentation. It's named as getLastModifiedByProperty() !!! Now my code look like as:
    PHP Code:
        public static String getLastModifiedByUser(File file) throws IOException, OpenXML4JException, XmlException {
            OPCPackage pkg = OPCPackage.open(file);
            POIXMLProperties xmlProps = new POIXMLProperties(pkg);
            PackagePropertiesPart propertiesPart = xmlProps.getCoreProperties().getUnderlyingProperties();
            return propertiesPart.getLastModifiedByProperty().getValue();
        }
    Now I've another problem. I don't write some value in this attribute calling the method setLastModifiedByUser(String user). My method here:
    PHP Code:
        public static void setLastModifiedByUser(File file, File newFile, String contentType, String user) throws IOException, InvalidFormatException {
            OPCPackage pkg = OPCPackage.open(file);
            XSSFWorkbook wb = new XSSFWorkbook(pkg);
            POIXMLProperties xmlProps = wb.getProperties();
            POIXMLProperties.CoreProperties coreProps = xmlProps.getCoreProperties();
            //coreProps.setLastModifiedByUser(contentType);
            coreProps.set;
            FileOutputStream fos = new FileOutputStream(newFile);
            writeData(fos, wb, pkg);
        }
    In the row:
    PHP Code:
            coreProps.set;
    IDE don't offer me method setLastModifiedByUser(). Because?
    Last edited by hoz; 01-11-2017 at 09:11 PM.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    19,493
    Rep Power
    29

    Default Re: How correct to set LastModifiedByProperty ?

    Sorry, I don't know anything about the packages and classes you are trying to use.
    Is there an API doc for the classes and packages you are using? They should show you what methods are available for the classes you are using.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,130
    Rep Power
    23

    Default Re: How correct to set LastModifiedByProperty ?

    Well, the class you linked to was the CoreProperties class.
    The class you are using in the first code is the PackagePropertiesPart class.
    They're different.

    For the second one I don't know.
    Different versions of the code?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. can u tell me w/c one is correct?
    By akocnivek in forum New To Java
    Replies: 4
    Last Post: 10-21-2012, 10:03 AM
  2. Correct implementation of EDT
    By robs in forum AWT / Swing
    Replies: 9
    Last Post: 06-15-2012, 05:31 PM
  3. Please help - can't seem to correct this...
    By jmjbreezin in forum New To Java
    Replies: 7
    Last Post: 05-09-2011, 01:39 PM
  4. keyTyped is it correct
    By aizen92 in forum New To Java
    Replies: 18
    Last Post: 04-03-2011, 01:47 PM
  5. Are my comments correct?
    By twiggy62 in forum New To Java
    Replies: 2
    Last Post: 02-08-2010, 06:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •