search

Home  >  Q&A  >  body text

java - About using POI to parse the value of time grid in excel

When parsing excel, a certain cell is stored as "8:00", but the parsed value is "31-December-1899". . . .
Black question mark face? ? ?
How is this going? No error was reported. The project requirement is that I can parse it out as a string according to what the customer writes. Everyone's explanations on the Internet are all parsed according to a fixed format. My requirement is that I can take out what the customer writes. How should I do it?
I looked at the excel format and the format is time. It will be fine after setting it to text. However, according to the customer's condition that he does not know, does not know, and will not change it, I would like to ask if I can solve this problem through code. Is there a problem?

大家讲道理大家讲道理2756 days ago871

reply all(1)I'll reply

  • PHP中文网

    PHP中文网2017-05-17 10:02:34

    The time in excel is actually a string of numbers stored. The value of the cell you see is the result after formatting. When poi reads the cell, no matter what format the user uses in excel to display the value, as long as it is in date format You can tell it by writing it like this using poi

    if (cellType == org.apache.poi.ss.usermodel.Cell.CELL_TYPE_NUMERIC) {
    
          if (DateUtil.isCellDateFormatted(cell)) {
    
            value = cell.getDateCellValue().toString();
    
          }
    }

    If it is in text format, just read it directly into text

    reply
    0
  • Cancelreply