Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Save results in an excel file

  1. #1
    Junior Member
    Join Date
    Jul 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Save results in an excel file

    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);
    }
    }
    }


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Save results in an excel file

    Did you not like the help you received elsewhere?
    This thread has been cross posted here:

    http://www.java-forums.org/apache-poi/61783-save-results-excel.html

    Although cross posting is allowed, for everyone's benefit, please read:

    Java Programming Forums Cross Posting Rules

    The Problems With Cross Posting


Similar Threads

  1. trying to save data onto a file
    By DanTheSand in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: December 13th, 2011, 09:58 AM
  2. [SOLVED] Very strange results when reading from a test file
    By DougFane in forum File I/O & Other I/O Streams
    Replies: 10
    Last Post: September 11th, 2011, 06:30 PM
  3. Replies: 1
    Last Post: August 3rd, 2011, 02:28 PM
  4. insert(embed) a file object (.txt file) in MS excel sheet using java.
    By jyoti.dce in forum What's Wrong With My Code?
    Replies: 1
    Last Post: August 12th, 2010, 08:16 AM
  5. Saving .jsp page as .pdf file while generating report for struts based web application
    By ravindra_kumar_tiwari in forum JavaServer Pages: JSP & JSTL
    Replies: 3
    Last Post: August 12th, 2008, 09:32 AM

Tags for this Thread