https://issues.apache.org/bugzilla/show_bug.cgi?id=50697

trainees <[email protected]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |

--- Comment #4 from trainees <[email protected]> 2011-02-01 05:26:41 EST 
---
This is the function i am using. When it reads the 'time' field in the attached
excel, the data obtained is '31-Dec-1899' instead of actual data. How can we
get the actual data?


public void displayFromExcel(String xlsPath, String sheetName) {
        System.out.println("In POIExcelReader :: method
===========displayFromExcel");
        InputStream inputStream = null;

        try {
            inputStream = new FileInputStream(xlsPath);
        } catch (FileNotFoundException e) {
            System.out.println("File not found in the specified path.");
            e.printStackTrace();
        }

        POIFSFileSystem fileSystem = null;

        try {
            fileSystem = new POIFSFileSystem(inputStream);

             this.workBook = new HSSFWorkbook(fileSystem);
             this. sheet = workBook.getSheetAt(0);
            if (!sheetName.equals("")) {
                sheet = workBook.getSheet(sheetName);
            }
            if(sheet != null){
           Iterator<Row> rows = sheet.rowIterator();
//Iterator<HSSFRow> rows     = sheet.rowIterator ();
            this.excelData = new ArrayList<ArrayList>();
            this.excelRows = sheet.getPhysicalNumberOfRows();

            ///

//            System.out.println("the total number of rows are" + rows);

            int cols = 0; // No of columns
            int tmp = 0;

            // This trick ensures that we get the data properly even if it
doesn't start from first few rows
            for (int i = 0; i < 10 || i < this.excelRows; i++) {
                Row erow = sheet.getRow(i);
            //  System.out.println("get cell "+erow.getCell(0));
                if (erow != null) {
                    tmp = sheet.getRow(i).getPhysicalNumberOfCells();
                    //out.println("tmp value"+tmp);
                    if (tmp > cols) {
                        cols = tmp;
                    }

                }
            }
            this.excelCols = cols;
            this.excelColDataType = new ArrayList();
            this.excelColDataSize = new ArrayList();

            for (int c = 0; c < cols; c++) {
                this.excelColDataType.add("Varchar");
                this.excelColDataSize.add("0");
            }
            CommonFunctions commonFunctions = new CommonFunctions();
            int testrow=0;
            while (rows.hasNext()) {
//HSSFRow row = rows.next ();
                Row row = rows.next();
                ArrayList rowData = new ArrayList(cols);

// display row number in the console.
//                System.out.println("Row No.: " + row.getRowNum());

// once get a row its time to iterate through cells.
//Iterator<HSSFCell> cells = row.cellIterator ();
                Iterator<Cell> cells = row.cellIterator();
                int c = 0;

                while (cells.hasNext()) {
//HSSFCell cell = cells.next ();
                    Cell cell = cells.next();

                  // System.out.println("Cell No.: " +
cell.getColumnIndex());//.getCellNum ());

                    if (cell != null && cell.toString() !="")
                    {
                       if(cell.getCellType() ==Cell.CELL_TYPE_NUMERIC )//Lilu
added on 2010 Dec 9
                       {
                       
rowData.add(String.valueOf((long)cell.getNumericCellValue()));
                        }
                       else
                       {
                           rowData.add(cell.toString());
                        }
//                   
                        switch (cell.getCellType()) {
                            case Cell.CELL_TYPE_NUMERIC: {
                                break;
                            }

                            case Cell.CELL_TYPE_STRING: {

                                RichTextString richTextString =
cell.getRichStringCellValue();
//                                System.out.println("String value: " +
richTextString.getString());

                                break;
                            }

                            default: {

                                // types other than String and Numeric.
                                System.out.println("Type not supported.");

                                break;
                            }
                        }
                    } else {
                        rowData.add("");
                    }
                    c++;
                }
               // System.out.println("rowData "+rowData);
                this.excelData.add(rowData);

            }
            }
//            System.out.println("Excel Data Size read: " +
this.excelData.size() + "~~~~" + this.excelData);
//            System.out.println("Excel Data Type size: " +
this.excelColDataType.size());
//            System.out.println("Excel Data Type read: " +
this.excelColDataType);
//            System.out.println("Excel Data Length read: " +
this.excelColDataSize);
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("Error in POIExcelReader :: method
==============displayFromExcel=====>"+e.getMessage()+e.getCause());
        }
    }

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to