Reputation: 758
I need to export some data from my Java app to Excel or Word file. It can be tables, bars, graphs... So, what is the best way to do this? In C# I used to do it via the standard library, but I don't know how to do this in Java.
Oh, and I also wanted to ask about DCOM interface. Can I use it somehow without running Excel?
Upvotes: 0
Views: 311
Reputation: 6016
You can have a look at the following libraries
http://jexcelapi.sourceforge.net/
Upvotes: 1
Reputation: 735
The easiest way to export data to excel is using csv format.
Here you have an example from mkyong.com/java/how-to-export-data-to-csv-file-java:
package com.mkyong.test;
import java.io.FileWriter;
import java.io.IOException;
public class GenerateCsv
{
public static void main(String [] args)
{
generateCsvFile("c:\\test.csv");
}
private static void generateCsvFile(String sFileName)
{
try
{
FileWriter writer = new FileWriter(sFileName);
writer.append("DisplayName");
writer.append(',');
writer.append("Age");
writer.append('\n');
writer.append("MKYONG");
writer.append(',');
writer.append("26");
writer.append('\n');
writer.append("YOUR NAME");
writer.append(',');
writer.append("29");
writer.append('\n');
//generate whatever data you want
writer.flush();
writer.close();
}
catch(IOException e)
{
e.printStackTrace();
}
}
}
Upvotes: 1