0

I generate a heavy file using Apache POI within 10 minutes. To minimize the memory usage and time, I generate the file only when I detect a change in my record. If not, I will just fetch the old most recent Excel file for download. The problem is how can I get the creation date of the old Excel file? I am thinking of using the Apache's PackageProperties class although I don't know how to achieve that.

  1. Get the file via FileInputStream.
  2. Read that file via new XSSFWorkbook(FileInputStream inputStream).
  3. I don't know the next step here to connect #2 and #4.
  4. Next is get the PackageProperties attribute of that workbook.
  5. Use the PackageProperties.getCreatedProperty() to get the creation date.
  6. If there is a change detected after the creation date of the file, we then start generating the file, then overwrite the old version of the file with the new one, then proceeds to download. If there are no changes detected, proceeds to download the previous file.

Now, how can I get that PackageProperties attribute of the workbook?

I had checked this other entry with a similar case (but using a CSV rather than Excel), but it seems using the last modified property of the file is not always identical to the creation date.

Gideon
  • 1,469
  • 2
  • 26
  • 57
  • 1
    https://stackoverflow.com/questions/2723838/determine-file-creation-date-in-java – Rao Jun 27 '17 at 13:53
  • Why not just fetch the creation / modified date off the `File` object? – Gagravarr Jun 27 '17 at 14:45
  • In some cases the Excel file is uploaded via a web page, or received in an e-mail. So the original file is not available for query. It would be useful and reliable to get this information from the content of the file. – Farsee May 17 '21 at 17:57

1 Answers1

1

For version 3.14 you can use:

((XSSFWorkbook) workbook).getPackage().getPackageProperties().getCreatedProperty().getValue()
EQuadrado
  • 221
  • 4
  • 4