0

In my application we generate Excel files using JExcel API which allows us to use XLS templates file. Now we must also manage XLSX format, but JExcel can not handle this format. What other API can be used ? I wanted to use POI but it does not take into account the templates. This forces us to change the code to fully recreated a file each time.

Thank's.

Ousmane MBINTE
  • 664
  • 4
  • 15
  • 37
  • What do you mean by `POI but it does not take into account the templates`? There's no problem opening one Excel file in POI which is your template, writing in a bunch of values then saving the new one, for example – Gagravarr Aug 12 '14 at 11:14

1 Answers1

0

The format xlsx is just a zip of some XML files, and some other files maybe.

You could use ZipFile, but a Zip File System could be easiser to operate on single embedded XML files:

    Map<String, String> zipProperties = new HashMap<>();
    zipProperties.put("encoding", "UTF-8");
    try (FileSystem zipFS = FileSystems.newFileSystem(docxUri,
            zipProperties)) {
        Path mediaPath = zipFS.getPath("/word/media");
        ...

You can copy/rename/move and so on. Excel is a bit harder, as it uses a shared.xml with shared strings.

This approach allows to keep near to some current Excel variant, which apache POI seems to have difficulty to achieve.

Joop Eggen
  • 107,315
  • 7
  • 83
  • 138