Skip to main content

Getting Started with OpenXLS

This section is intended to get you started quickly programming with OpenXLS.

OpenXLS is designed for use by programmers familiar with the Java syntax, the concepts of file templates, and spreadsheets.

Basic use of the API requires the following steps:

  1. Copy OpenXLS.jar and openxls.lic to a project directory. Make sure that the jar is in the classpath of your project. The OpenXLS.jar file needs to be on your classpath in order for the JVM to find the OpenXLS class files.

  2. In your Java code, import the com.valkyrlabs.OpenXLS.* package.

  3. Create a new WorkBookHandle. This can either be a new, empty WorkBook with three sheets, or you can parse an existing XLS file in the form of a byte array from a file or other data source. Review the WorkBookHandle constructors in the API documentation to see which WorkBookHandle is appropriate for your application.

  4. Work with a WorkSheet by using the WorkBookHandle.getWorkSheet(String sheetname) method. You must catch the WorkSheetNotFoundException in case the expected sheet does not exist already in the file.

  5. Access Cell values using the WorkSheetHandle.getCell(Sheetname:CellAddress) method. You must catch the CellNotFoundException in case the expected Cell does not exist already in the file. You can add a new Cell to the sheet and get a CellHandle with one line of code by using the CellHandle WorkSheetHandle.add(Object ob, String address) method.

  6. Set and get the value of Cells using CellHandle.setCellVal(Object ob) and Object CellHandle.getCellVal() methods.

  7. Stream the WorkBook bytes to an output file using the WorkBookHandle.getBytes() method. If you are writing a web application, you can send the bytes over a ServletResponse to a web browser or you can write them out to a file or to any byte array consumer.