Hi,

I am writing some data (Strings, Numeric as well as Dates) into an excel.
The structure of the sheet is similar to what's shown below:
STR_COL, DATE1_COL, NUM1_COL, DATE2_COL, DATE3_COL, DATE4_COL, NUM2_COL,
DATE5_COL

The dates are formatted with a custom formatter allowing for Timestamp.
On creation, the format structure of the sheet is fine.
On editing (not through code, manually updating the sheet) the NUM2_COL only
after I have edited a DATE*_COL in the sheet, the format of the NUM2_COL
changes to the date format automatically. Strangely, this behaviour is not
seen with the NUM1_COL.

Following is some part of the code I am using...
sheet3 = wb.createSheet("Sheet_3");
        createHeaderRow(2, sheet3);
        // Set the cell format for the dates
        HSSFCellStyle cellStyle = wb.createCellStyle();
        HSSFCellStyle cellStyleDate = wb.createCellStyle();
        HSSFCellStyle cellStyleGeneral = wb.createCellStyle();
        HSSFCellStyle cellStyleDateGrayed = wb.createCellStyle();
        HSSFDataFormat dataFormat = wb.createDataFormat();
        cellStyleDate.setDataFormat(dataFormat.getFormat("dd-MMM-yyyy
hh:mm:ss"));

cellStyleGeneral.setDataFormat(dataFormat.getBuiltinFormat("General"));
        cellStyleDateGrayed.setDataFormat(dataFormat.getFormat("dd-MMM-yyyy
hh:mm:ss"));
        cellStyleDateGrayed.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);

cellStyleDateGrayed.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);

        styles.add(cellStyleGeneral);
        styles.add(cellStyleDate);
        styles.add(cellStyleDateGrayed);

................

        HSSFRow row = null;
        HSSFCell cell = null;

        row = sheet.createRow(rowNumber);
        // STR1
        cell = row.createCell(0);
        cell.setCellType(HSSFCell.CELL_TYPE_STRING);
        cell.setCellStyle(styles.get(0));
        cell.setCellValue(str1);
        // DATE1
        cell = row.createCell(1);
        cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
        cell.setCellStyle(styles.get(1));
        cell.setCellValue(date1);
        // NUM1
        cell = row.createCell(2);
        cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
        cell.setCellStyle(styles.get(0));
        cell.setCellValue(num1);
        // DATE2
        cell = row.createCell(3);
        cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
        cell.setCellStyle(styles.get(1));
        cell.setCellValue(date2);
        // DATE3
        cell = row.createCell(4);
        cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
        cell.setCellStyle(styles.get(1));
        cell.setCellValue(date3);
        // DATE4
        cell = row.createCell(5);
        cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
        cell.setCellStyle(styles.get(1));
        cell.setCellValue(date4);
        // NUM2
        cell = row.createCell(6);
        cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
        cell.setCellStyle(styles.get(0));
        cell.setCellValue(num2);
        // DATE5
        cell = row.createCell(7);
        cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
        cell.setCellStyle(styles.get(2));
        Calendar prepCalendar = Calendar.getInstance();
        prepCalendar.setTime(date3);
        prepCalendar.add(Calendar.HOUR, 8);
        cell.setCellValue(prepCalendar.getTime());


Smriti

Reply via email to