I have a large simulation and I would like to save my results in an excel file.
I have a main class and a class where there are the results, and I ama able to print them, but I can't save them in a file.
How can I do it? Where do I have to put the parts here...? I can create a file with only the last parameters printed now...
Thanks for your help, sorry for the silly question.
This is the code for excel:
import java.io.*;
import java.io.FileNotFoundException.*;
import java.util.Date;
import jxl.*;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFCell;
import java.util.Arrays.*;
public class CreateExcelFile {
public static void main(String[]args){
try{
String filename="...Results.xls" ;
HSSFWorkbook wb=new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("BTObserver");
HSSFRow row;
HSSFCell cell;
for (short rowIndex = 0; rowIndex < 1000; rowIndex++) {
row.createCell(1).setCellValue(((BitTorrent)(Netwo rk.get(i).getProtocol(pid))).getThisNodeID());
row.createCell(2).setCellValue("(" + peerStatus + ")");
row.createCell(3).setCellValue(numberOfCompletedPi eces);
row.createCell(4).setCellValue(((BitTorrent)(Netwo rk.get(i).getProtocol(pid))).nPiecesDown);
row.createCell(5).setCellValue(((BitTorrent)(Netwo rk.get(i).getProtocol(pid))).nPiecesUp);
row.createCell(6).setCellValue(CommonState.getTime ());
}
FileOutputStream fileOut = new FileOutputStream(filename);
wb.write(fileOut);
fileOut.close();
System.out.println("Your excel file has been generated!");
}catch(Exception ex){
System.err.println(ex);
}
}
}