Home arrow static arrow Java Programming [Archive] - jakarta POI
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - jakarta POI
This topic has 1 reply on 1 page.

Registered: 5/26/04
jakarta POI  
Aug 5, 2004 7:41 AM

The problem is that when i open the XLS file that I create using POI the DATE Cells are not formatted as DATE Cells and the code is well.
private void llenarFila(ResultSet rs, HSSFRow row, HSSFWorkbook wb) throws SQLException {                ResultSetMetaData rsmd = rs.getMetaData();                //DateFormat df = DateFormat.getDateInstance();                SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");                HSSFDataFormat format = wb.createDataFormat();                SimpleDateFormat formatter2 = new SimpleDateFormat("dd/MM/yyyy", new Locale("es"));                //DateFormat formatter2 = DateFormat.getInstance();                for(int i = 1 ; i <= rsmd.getColumnCount() ; i++) {                        int columnDataType = rsmd.getColumnType(i);                        System.out.println(columnDataType);                        HSSFCell cell = row.createCell((short) (i-1));                                                                                                                         if(columnDataType == 93) { // java.sql.Types.DATE y oracle.jdbc.driver.OracleTypes.DATE son 91 y no funcionan... de la basde devuelve 93 para DATE                                                             try {                                           Object obj = rs.getObject(i);                                        if(obj != null) {                                                String dateString = ((Object)rs.getObject(i)).toString();                                                java.util.Date date1 = formatter.parse(dateString);                                                String newDateString = formatter2.format(date1);                                                                                                                         System.out.println(date1.toString());                                                java.util.Date date = formatter2.parse(newDateString);                                                System.out.println(date.toString());                                                HSSFCellStyle cellStyle = wb.createCellStyle();                                                cellStyle.setDataFormat(format.getFormat("dd/mm/yyyy"));                                                cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);                                                cell.setCellStyle(cellStyle);                                                cell.setCellValue(date); //....  the rest...}

Any ideas ? Thanks a lot. This is going me crazy since yesterdya.

Registered: 1/31/02
Re: jakarta POI  
Aug 5, 2004 7:51 AM (reply 1 of 1)

I've not used POI, but this might be helpful for you:



Good luck

This topic has 1 reply on 1 page.