public class createExcel {
public void write() throws IOException, WriteException {
WorkbookSettings wbSettings = new WorkbookSettings();
wbSettings.setLocale(new Locale("en", "EN"));
WritableWorkbook workbook1 =Workbook.createWorkbook(new File(file), wbSettings);
workbook1.createSheet("Niru ", 0);
WritableSheet excelSheet = workbook1.getSheet(0);
createLabel(excelSheet);
createContent(excelSheet,list);
workbook1.write();
workbook1.close();
}
public void createLabel(WritableSheet sheet)throws WriteException {
WritableFont times10pt = new WritableFont(WritableFont.createFont("D:\font\trebuct"),8);
// Define the cell format
times = new WritableCellFormat(times10pt);
// Lets automatically wrap the cells
times.setWrap(false);
WritableFont times10ptBoldUnderline = new WritableFont(
WritableFont.createFont("D:\font\trebuct"), 9, WritableFont.BOLD, false,
UnderlineStyle.NO_UNDERLINE);
timesBoldUnderline = new WritableCellFormat(times10ptBoldUnderline);
sheet.setColumnView(0,15);
sheet.setColumnView(1,13);
// Write a few headers
addCaption(sheet, 0, 0, "Business Date");
addCaption(sheet, 1, 0, "Dealer ID");
}
private void createContent(WritableSheet sheet, ArrayList list) throws WriteException,RowsExceededException {
// Write a few number
for (int i = 1; i < 11; i++) {
for(int j=0;j<11;j++){
// First column
addNumber(sheet, i, j,1);
// Second column
addNumber(sheet, 1, i, i * i);
}
}
}
private void addCaption(WritableSheet sheet, int column, int row, String s) throws RowsExceededException, WriteException {
Label label;
label = new Label(column, row, s, timesBoldUnderline);
sheet.addCell(label);
}
private void addNumber(WritableSheet sheet, int row,int column,
Integer integer) throws WriteException, RowsExceededException {
Number number;
number = new Number(column,row, integer, times);
sheet.addCell(number);
}
public static void main(String[] args) {
JButton myButton0 = new JButton("Advice_Report");
JButton myButton1 = new JButton("Position_Report");
JPanel bottomPanel = new JPanel();
bottomPanel.add(myButton0);
bottomPanel.add(myButton1);
myButton0.addActionListener(this);
myButton1.addActionListener(this);
createExcel obj=new createExcel();
obj.setOutputFile("c;\\temp\\swings\\jack.xls");
try{
obj.write();
}catch(Exception e){}
}
and so on. it working fine.
i have jxl.jar and ojdbc14.jar files(need this jar file for Excelsheet creation and DB connection )and createExcel.class(.class file) file.
how to make this code as executable jar file.
There are several ways:
Create a jar file and put your classes (without dependencies) there. Use some tool (any IDE has it) to do this and specify class with main function. You can also do it manually from command-line. When user want to run it he should specify classpath and all dependencies should be in that classpath.
Create the same jar and create .bat or .sh file in which set classpath and run your jar.
Create cross-platform installer with some special tool (but good tools aren’t free).