|
|
 |
OfficeWriter Home > officewriter-305.aspx |
| How
POI Stacks Up Against OfficeWriter |
 |
| |
| OfficeWriter
Requires Only 25 Lines of Code: |
| |
| In just under 25 lines of actual
code (comments & spacing not included), OfficeWriter creates the same
spreadsheet that it took 100
lines to create with POI.
Discover how to generate native Excel and Word reports with OfficeWriter
from your front-end
Java™ web application. |
| |
import java.util.Date;
import com.softartisans.excelwriter.ExcelTemplate;
/**
* An ExcelWriter test that creates the same output file as POITest.java.
*/
public class XLWTest {
public static void main(String[] args) throws Exception {
long startTime, stopTime;
startTime = System.currentTimeMillis();
// Create the data objects (this would usually
// be a ResultSet or something similar.
Object[][] data = new Object[10][100];
for (int i=0; i<data.length; i++) {
for (int j=0; j<data[0].length; j++) {
// String data
if (i==0) data[i][j] = "Product " + j;
else if (i<9) {
data[i][j] = new Integer((int)(Math.random()*100));
}
else data[i][j] = new Date();
}
}
// Create the ExcelTemplate object and populate it.
ExcelTemplate xlt = new ExcelTemplate();
xlt.open("template.xls");
xlt.setDataSource(data,null,"Data");
xlt.process();
xlt.save("XLWOut.xls");
stopTime = System.currentTimeMillis();
System.out.println("XLW generation took "
+(stopTime-startTime)+"ms");
}
}
|
|
|
|
|
|