Index: tmp/org.txm.libs.office/src/org/txm/libs/office/WriteODS.java
===================================================================
--- tmp/org.txm.libs.office/src/org/txm/libs/office/WriteODS.java	(revision 0)
+++ tmp/org.txm.libs.office/src/org/txm/libs/office/WriteODS.java	(revision 2343)
@@ -0,0 +1,162 @@
+package org.txm.libs.office;
+
+import java.io.File;
+import java.util.ArrayList;
+
+import org.odftoolkit.simple.SpreadsheetDocument;
+import org.odftoolkit.simple.table.Cell;
+import org.odftoolkit.simple.table.Row;
+import org.odftoolkit.simple.table.Table;
+
+public class WriteODS {
+	
+	SpreadsheetDocument spreadsheet;
+	Table table;
+	File newODSFile;
+	
+	public WriteODS(File newODSFile) throws Exception {
+		this.newODSFile = newODSFile;
+		this.spreadsheet = SpreadsheetDocument.newSpreadsheetDocument();
+	}
+	
+	public void newTable(String name) {
+		if (name != null && name.length() > 0) {
+			this.table = spreadsheet.appendSheet(name);
+		} else {
+			this.table = spreadsheet.addTable();
+		}
+	}
+	
+	/**
+	 * 
+	 * @param nRows rows are inserted if nRows > 0
+	 * @param nColumns columns are inserted if nColumns > 0
+	 */
+	public void declareRowsAndColumns(int nRows, int nColumns) {
+		if (table == null) throw new IllegalStateException("no table set with 'newtTable(...)'");
+		if (nRows > 0) {
+			table.appendRows(nRows);
+		}
+		
+		if (nColumns > 0) {
+			table.appendColumns(nColumns);
+		}
+	}
+	
+	protected void writeLine(Object[] line, Row row) {
+		if (table == null) throw new IllegalStateException("no table set with 'newtTable(...)'");
+		for (int iCol = 0; iCol < line.length; iCol++) {
+			Cell cell = row.getCellByIndex(iCol);
+			if (cell != null) {
+				writeCell(cell, line[iCol]);
+			} else {
+				throw new IllegalStateException("cannot get col at "+iCol);
+			}
+		}
+	}
+	
+	public void writeLine(Object[] line, int iRow) {
+		if (table == null) throw new IllegalStateException("no table set with 'newtTable(...)'");
+		Row row = table.getRowByIndex(iRow);
+		if (row != null) {
+			writeLine(line, row);
+		} else {
+			throw new IllegalStateException("cannot get row at "+iRow);
+		}
+	}
+	
+	public void writeLine(ArrayList<?> line, int iRow) {
+		if (table == null) throw new IllegalStateException("no table set with 'newtTable(...)'");
+		Row row = table.getRowByIndex(iRow);
+		if (row != null) {
+			writeLine(line.toArray(), row);
+		} else {
+			throw new IllegalStateException("cannot get row at "+iRow);
+		}
+	}
+	
+	public void writeLine(Object[] line) {
+		if (table == null) throw new IllegalStateException("no table set with 'newtTable(...)'");
+		Row row = table.appendRow();
+		writeLine(line, row);
+	}
+	
+	public void writeLine(ArrayList<?> line) {
+		if (table == null) throw new IllegalStateException("no table set with 'newtTable(...)'");
+		Row row = table.appendRow();
+		writeLine(line.toArray(), row);
+	}
+	
+	public void save() throws Exception {
+		spreadsheet.save(newODSFile);
+	}
+	
+	public static void write(File newODFFile, Object[][] data) throws Exception {
+		
+		if (data.length == 0) throw new IllegalArgumentException("no data to write in " + newODFFile);
+		
+		SpreadsheetDocument spreadsheet = SpreadsheetDocument.newSpreadsheetDocument();
+		Object[] firstLine = data[0];
+		Table table = spreadsheet.addTable();
+		table.appendRows(data.length);
+		table.appendColumns(firstLine.length);
+		
+		for (int iRow = 0; iRow < data.length; iRow++) {
+			Row row = table.appendRow();
+			Object[] line = data[iRow];
+			for (int iCol = 0; iCol < line.length; iCol++) {
+				Cell cell = row.getCellByIndex(iCol);
+				writeCell(cell, line[iCol]);
+			}
+		}
+		
+		spreadsheet.save(newODFFile);
+	}
+	
+	public static void write(File newODFFile, ArrayList<ArrayList<?>> data) throws Exception {
+		
+		if (data.size() == 0) throw new IllegalArgumentException("no data to write in " + newODFFile);
+		
+		SpreadsheetDocument spreadsheet = SpreadsheetDocument.newSpreadsheetDocument();
+		ArrayList<?> firstLine = data.get(0);
+		Table table = spreadsheet.addTable();
+		table.appendRows(data.size());
+		table.appendColumns(firstLine.size());
+		
+		for (int iRow = 0; iRow < data.size(); iRow++) {
+			Row row = table.appendRow();
+			ArrayList<?> line = data.get(iRow);
+			for (int iCol = 0; iCol < line.size(); iCol++) {
+				Cell cell = row.getCellByIndex(iCol);
+				writeCell(cell, line.get(iCol));
+			}
+		}
+		
+		spreadsheet.save(newODFFile);
+	}
+	
+	private static void writeCell(Cell cell, Object object) {
+		
+		if (object == null) cell.removeContent();
+		
+		if (object instanceof String) {
+			cell.setStringValue(object.toString());
+		}
+		else if (object instanceof Boolean) {
+			cell.setBooleanValue((Boolean) object);
+		}
+		else if (object instanceof Double) {
+			cell.setDoubleValue((Double) object);
+		}
+		else {
+			cell.setStringValue(object.toString());
+		}
+	}
+	
+	public static void main(String[] args) throws Exception {
+		
+		File file = new File("/home/mdecorde/TEMP/test_writing.ods");
+		ArrayList<ArrayList<String>> table = new ArrayList<ArrayList<String>>();
+		
+	}
+}

Property changes on: tmp/org.txm.libs.office/src/org/txm/libs/office/WriteODS.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

