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