/************************************************************************************ * Copyright (C) 2008 by Politehnica University of Bucharest and Rutgers University * All rights reserved. * Refer to LICENSE for terms and conditions of use. ***********************************************************************************/ package vnsim.network.dsrc; import java.io.*; import org.dom4j.*; import java.util.HashMap; import java.util.ArrayList; public class ExcelWriter { private File outputFile = null; /** Creates a new instance of JavaExcel */ public ExcelWriter() { } //This function writes the SpreadsheetML document to a file public void write(String file,ArrayList results) throws Exception { outputFile = new File(file); Document doc = DocumentHelper.createDocument(); HashMap pmap = new HashMap(); pmap.put("progid","Excel.Sheet"); doc.addProcessingInstruction("mso-application",pmap); doc.add(this.createElements(results)); FileWriter out = new FileWriter(outputFile); doc.write(out); out.flush(); out.close(); } //This function creates the root of the SpreadsheetML and //populates it with necesary elements. private Element createElements(ArrayList results) throws Exception { //Create all Elements Element workbook = this.createWorkbook(); Element worksheet = this.createWorksheet("Simualtion Data"); workbook.add(worksheet); Element table = this.createTable(); worksheet.add(table); Element row1 = this.createRow("1"); table.add(row1); Element cellA1 = this.createCell(); row1.add(cellA1); Element dataA1 = this.createData("String","Received Packets lost/ok"); cellA1.add(dataA1); Element row2 = this.createRow("2"); table.add(row2); Element cell=this.createCell(); row2.add(cell); Element data = this.createData("String","Ok packets"); cell.add(data); for(int i=1;i