I want to create an excel file with java and write data to it, here is what I have so far. How do I create new worksheets and add data to them? Is there a better way of doing it?
import java.io.*;
import java.text.DateFormat;
import java.util.Date;
import java.io.File;
public class DiskspaceRpt
{
public static void main(String args[])
throws java.io.IOException
{
Date now = new Date();
String fileName = ("Diskspace_" + DateFormat.getDateInstance(DateFormat.SHORT).format(now)).replace('/', '-') + ".xls";
System.out.println(fileName);
try
{
/* Set the second parameter
true to append, false to overwrite */
FileWriter outfile = new FileWriter(fileName, true);
BufferedWriter out = new BufferedWriter(outfile);
/* Best to write TAB-separated
values so Excel can easily format the
values as cell-contents */
out.write("Some\tExcel\tCell\tValues");
out.newLine();
out.close();
outfile.close();
}
catch (IOException e)
{
e.printStackTrace();
};
System.in.read();
}
}
import java.io.*;
import java.text.DateFormat;
import java.util.Date;
import java.io.File;
public class DiskspaceRpt
{
public static void main(String args[])
throws java.io.IOException
{
Date now = new Date();
String fileName = ("Diskspace_" + DateFormat.getDateInstance(DateFormat.SHORT).format(now)).replace('/', '-') + ".xls";
System.out.println(fileName);
try
{
/* Set the second parameter
true to append, false to overwrite */
FileWriter outfile = new FileWriter(fileName, true);
BufferedWriter out = new BufferedWriter(outfile);
/* Best to write TAB-separated
values so Excel can easily format the
values as cell-contents */
out.write("Some\tExcel\tCell\tValues");
out.newLine();
out.close();
outfile.close();
}
catch (IOException e)
{
e.printStackTrace();
};
System.in.read();
}
}