Hi
With a little bit of help from this forum and a lot of help from google I have written a java service using JExcel package/jxl.jar file. The service takes some inputs and generates a formatted(with different fonts/style/colors/cell sizes etc) MS Excel sheet and writes it to a location. For anyone who is stuck with generating formatted excel , here is a part of code. This may give you an idea …
[highlight=java]try
{
IDataCursor pipelineCursor2 = pipeline.getCursor();
String in1 = IDataUtil.getString( pipelineCursor2, “in1” );
String filename = “F:\Napster\output.xls”;
WorkbookSettings ws = new WorkbookSettings();
ws.setLocale(new Locale(“en”, “EN”));
WritableWorkbook workbook = Workbook.createWorkbook(new File(filename), ws);
WritableSheet s = workbook.createSheet(“Sheet1”, 0);
String S1,T1,J1;
/* Format the Font */
WritableFont wf1 = new WritableFont(WritableFont.ARIAL, 10, WritableFont.BOLD);
WritableCellFormat cfbold = new WritableCellFormat(wf1);
cfbold.setWrap(true);cfbold.setBackground(Colour.ICE_BLUE);
cfbold.setBorder(Border.ALL, BorderLineStyle.THIN ,Colour.BLACK);
WritableFont wf2 = new WritableFont(WritableFont.ARIAL, 10);
WritableCellFormat cf1 = new WritableCellFormat(wf2);
cf1.setWrap(true);cf1.setBorder(Border.ALL, BorderLineStyle.THIN ,Colour.BLACK);
IDataCursor pipelineCursor = pipeline.getCursor();
IData[] inputList = IDataUtil.getIDataArray( pipelineCursor, "final" );
for(int i=0;i<inputList.length;i++)
{
if ( inputList[i] != null)
{
WritableCellFormat cf;
if (i==0)
cf=cfbold;
else
cf=cf1;
int col=i;
IDataCursor inputCursor = inputList[i].getCursor();
S1 = IDataUtil.getString( inputCursor, "S1" );
Label l = new Label(0,col,S1,cf);
s.addCell(l);
s.setColumnView(0,15);
//s.setRowView(0,250);
T1 = IDataUtil.getString( inputCursor, "T1" );
l = new Label(1,col,T1,cf);
s.addCell(l);
J1 = IDataUtil.getString( inputCursor, "J1" );
l = new Label(5,col,J1,cf);
s.addCell(l);
s.setColumnView(5,40);
inputCursor.destroy();
}
}
int j=inputList.length+2;
s.mergeCells(0, j, 4, j);
Label name1 = new Label(0,j,"Name",cfbold);
s.addCell(name1);
//s.mergeCells(5, j, 6, j);
name1 = new Label(5,j,"id",cfbold);
s.addCell(name1);
j=j+1;
IDataCursor pipelineCursor12 = pipeline.getCursor();
String Name = IDataUtil.getString( pipelineCursor, "Name" );
String ID = IDataUtil.getString( pipelineCursor, "ID" );
s.mergeCells(0, j, 4, j);
name1 = new Label(0,j,Name,cf1);
s.addCell(name1);
name1 = new Label(5,j,ID,cf1);
s.addCell(name1);
workbook.write();
workbook.close();
}
catch (Exception ex)
{
IDataCursor pipelineCursor1 = pipeline.getCursor();
IDataUtil.put( pipelineCursor1, “exception”, ex.toString() );
pipelineCursor1.destroy();
}[/highlight]
thanks,
regards,
Napster