java - About using POI to parse the value of time grid in excel
大家讲道理
大家讲道理 2017-05-17 10:00:34
0
1
888

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?

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(1)
洪涛

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template