How to construct multipledata in a excel cell using Java
I am reading an excel sheet in netbeans using Java. In ONE CELL, i have multiple values in each line, like : 39N 98N 99N 12N and so on..
I did this,
for (Row row : sheet) {
if(row.getCell(0) != NULL) {
..... // get all the 4 values separately
}
}
I get all the 4 rows of dat开发者_如何学Pythona if its printed. But, how to get each row of data and store it separately?
Thanks Ramm
As you are using the Apache POI library, you can get the String out of the cell via the getStringCellValue
method and split it up at every whitespace (\s
in regex) using split
:
for (Row row : sheet) {
if(row.getCell(0) != NULL) {
String cellContents = row.getCell(0).getStringCellValue();
String[] splittedValues = cellContents.split("\\s");
}
}
splittedValues
would then be:
{
"39N",
"98N",
"99N",
"12N"
}
精彩评论