Java Excel API is an open source java library to read, write and modify Excel spread sheets.
This requires the library jxl-2.6.12.jar to be in classpath.
The following example shows how to copy and update Cells in Excel Spread sheet.
// Create cell font and format
WritableFont cellFont = new WritableFont(WritableFont.TIMES, 16);
cellFont.setColour(Colour.BLUE);
WritableCellFormat cellFormat = new WritableCellFormat(cellFont);
cellFormat.setBackground(Colour.ORANGE);
// Create the label, specifying content and format
Label label = new Label(1, 2, "ABCD", cellFormat);
sheet.addCell(label);
//Create copies of cell in a loop
WritableCell copiedCell = null;
WritableCellFormat cpCellFormat = new WritableCellFormat(cellFont);
cpCellFormat.setBackground(Colour.PINK);
for (int i = 0 ; i < 4 ; i ++) {
//Deep copy cell
copiedCell = sheet.getWritableCell(1, 2).copyTo(1, 4 + i);
copiedCell.setCellFormat(cpCellFormat);
sheet.addCell(copiedCell);
}
//Writes out the data held in this workbook in Excel format
workbook.write();
//Close and free allocated memory
workbook.close();
}