If you really want an Excel file, the best library for creating one is Andy Khan's JExcel.
I think you'd need one worksheet per flow, with .csv pairs for each one, sorted by time.
If these are graphs of a variable versus time, wouldn't "time" be the first value in each pair?
Here's how I'd do it. It works perfectly for the simple test case I supplied - it's working code that you'll be able to extend.
package jexcel;
import jxl.Workbook;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class JExcelUtils
{
public static void main(String[] args)
{
String fileName = ((args.length > 0) ? args[0] : "jexcel.xls");
Map<String, List<Pair>> csv = new HashMap<String, List<Pair>>()
{{
put("Flow1", fromArrayToList(new double[][]
{
{ 0.0, 0.0 },
{ 0.1, 1.0 },
{ 0.2, 2.0 },
{ 0.3, 3.0 },
{ 0.4, 4.0 },
{ 0.5, 5.0 },
}));
put("Flow2", fromArrayToList(new double[][]
{
{ 0.0, 0.0 },
{ 0.1, 1.0 },
{ 0.2, 4.0 },
{ 0.3, 9.0 },
{ 0.4, 16.0 },
{ 0.5, 25.0 },
}));
}};
WritableWorkbook excelContents = null;
try
{
File excelFile = new File(fileName);
excelContents = createExcel(excelFile, csv);
excelContents.write();
}
catch (IOException e)
{
e.printStackTrace();
}
catch (WriteException e)
{
e.printStackTrace();
}
finally
{
try { if (excelContents != null) excelContents.close(); } catch (Exception e) { e.printStackTrace(); }
}
}
public static List<Pair> fromArrayToList(double [][] input)
{
List<Pair> result = new ArrayList<Pair>();
for (int i = 0; i < input.length; ++i)
{
result.add(new Pair(input[i][0], input[i][1]));
}
return result;
}
public static WritableWorkbook createExcel(File excelFile, Map<String, List<Pair>> worksheets) throws IOException, WriteException
{
WritableWorkbook result = Workbook.createWorkbook(excelFile);
int order = 0;
for (String worksheetName : worksheets.keySet())
{
WritableSheet worksheet = result.createSheet(worksheetName, order++);
List<Pair> worksheetValues = worksheets.get(worksheetName);
for (int row = 0; row < worksheetValues.size(); ++row)
{
worksheet.addCell(new jxl.write.Number(0, row, worksheetValues.get(row).getX()));
worksheet.addCell(new jxl.write.Number(1, row, worksheetValues.get(row).getY()));
}
}
return result;
}
}
class Pair
{
private double x;
private double y;
Pair(double x, double y)
{
this.x = x;
this.y = y;
}
public double getX()
{
return x;
}
public double getY()
{
return y;
}
}