package com.java.myapp;
import java.io.File;
import jxl.Workbook;
import jxl.format.Colour;
import jxl.format.VerticalAlignment;
import jxl.write.Label;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
public class MyClass {
public static void main(String[] args) {
try{
Workbook template = Workbook.getWorkbook(new File("C:\\java\\Template.xls"));
String fileName = "C:\\java\\myExcel.xls";
WritableWorkbook workbook = Workbook.createWorkbook(new File(fileName),template);
//*** Create Font ***//
WritableFont fontBlue = new WritableFont(WritableFont.TIMES, 10);
fontBlue.setColour(Colour.BLUE);
//*** Create Format ***//
WritableCellFormat cellFormat = new WritableCellFormat(fontBlue);
cellFormat.setWrap(true);
cellFormat.setAlignment(jxl.format.Alignment.CENTRE);
cellFormat.setVerticalAlignment(VerticalAlignment.CENTRE);
cellFormat.setWrap(true);
cellFormat.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.HAIR,
jxl.format.Colour.BLACK);
//*** Sheet 1 ***//
WritableSheet ws1 = workbook.getSheet(0); // Copy from Sheet 0
ws1.setColumnView(0, 15); // Column 1
ws1.addCell(new Label(0,9,"Column 1",cellFormat));
ws1.addCell(new Label(0,10,"Column 1",cellFormat));
ws1.addCell(new Label(0,11,"Column 1",cellFormat));
ws1.addCell(new Label(0,12,"Column 1",cellFormat));
ws1.setColumnView(1, 15); // Column 2
ws1.addCell(new Label(1,9,"Column 2",cellFormat));
ws1.addCell(new Label(1,10,"Column 2",cellFormat));
ws1.addCell(new Label(1,11,"Column 2",cellFormat));
ws1.addCell(new Label(1,12,"Column 2",cellFormat));
workbook.write();
workbook.close();
System.out.println("Excel file created.");
}
catch (Exception e) {
e.printStackTrace();
}
}
}