Search code examples
javaexcelfilepega

Create Excel File With Limited Libraries in Java


I'm working in a framework that makes extensive use of excel documents, but the only imports it's using to do so are listed below:

java.io.*;
java.util.*;
java.util.regex.*;
java.util.zip.*;
javax.xml.parsers.*;
javax.xml.transform.*;
javax.xml.transform.dom.*;
javax.xml.transform.stream.*;
org.w3c.dom.*;

Because my workplace may not allow me to get the apache poi jar, how would I even begin to assemble an excel document using the above libraries?

The framework I'm working in is PRPC 7.x - most of the code it uses is proprietary and either hidden or incredibly inconvenient to get to, so it's rough trying to follow the breadcrumbs and mimic existing functionality.


Solution

  • There are two kinds of Excel files. The one is BIFF (Binary Interchange File Format) saved as *.xls files. The other is Office Open XML, a ZIPed directory structure containing XML files saved as *.xlsx files. The latter you can assemble using the showed libraries.

    You can simply create a simple *.xlsx file using Excel. Then open this *.xlsx file using a ZIP software. Now you can have a look at the directory structure of that ZIP archive and at the content of the XML files in it.

    Now the challenge is to create the needed XML files keeping the proper relationships between them and to pack them as an ZIP archive using the proper directory structure and then naming that ZIParchive *.xlsx.

    Belive me, it is a challenge ;-).

    https://en.wikipedia.org/wiki/Office_Open_XML