A pure Java library for OASIS Open Document files manipulation

Create a spreadsheet

With jOpenDocument, it's very easy to save any tabular data to an OpenDocument spreadsheet.



  // Create the data to save.
  final Object[][] data = new Object[6][2];
  data[0new Object[] { "January"};
  data[1new Object[] { "February"};
  data[2new Object[] { "March"};
  data[3new Object[] { "April"10 };
  data[4new Object[] { "May"15 };
  data[5new Object[] { "June"18 };

  String[] columns = new String[] { "Month""Temp" };

  TableModel model = new DefaultTableModel(data, columns);  
  // Save the data to an ODS file and open it.
  final File file = new File("temperature.ods");

As you can see in the code above, a spreadsheet can be generated directly from data by using the static method createEmpty of the class SpreadSheet with a javax.swing.TableModel as an argument. The only thing to be specified is the file where to save the data.

You will find in the SpreadSheet class different methods that let you define the version of the final generated document with the appropriate extension:

  • - OpenOffice 1 (.sxc)
  • - ODF 1.0 & OpenOffice 2+ (.ods)

If you want to know more, look at the package org.jopendocument.dom.spreadsheet