Answer the question
In order to leave comments, you need to log in
How to parse a record from Excel?
I have an xlsx file:
I need to parse and write to a new xlsx file + (parse "Order payment #632-966-417" and write to a new line)
How to implement it?
What I've done:
public static String parseFile(String name) throws IOException {
String result = "";
InputStream in = null;
XSSFWorkbook wb = null;
try {
in = new FileInputStream(name);
wb = new XSSFWorkbook(in);
}catch (IOException ex){
ex.printStackTrace();
}
Sheet sheet = wb.getSheetAt(0);
Iterator<Row> it = sheet.iterator();
while (it.hasNext()){
Row row = it.next();
Iterator<Cell> cells = row.iterator();
while (cells.hasNext()){
Cell cell = cells.next();
CellType cellType = cell.getCellType();
switch (cellType){
case STRING:
result += cell.getStringCellValue();
break;
case NUMERIC:
case FORMULA:
result += " " + cell.getNumericCellValue() + " ";
break;
default:
result += " ";
break;
}
}
result += "\n";
}
return result;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question