分析文件时出错:分析文件时出错:无法在Java的XSSF中分析excel文件
我试图用java将excel文件作为输入进行解析,我需要将文件中的前三行连接起来,并将它们作为一个标题放在第四行中,但文件解析对我不起作用,有什么想法吗
// FP&A Parse file with Headers
public List<Map<String, String>> fpaParseExcelFileWithHeaders(MultipartFile file, List<String> headersList) {
List<Map<String, String>> parsedFile = new ArrayList<>();
List<String> headers = headersList;
Map<String, String> cells = new HashMap<>();
try {
XSSFWorkbook workbook = new XSSFWorkbook(file.getInputStream());
// Get first/desired sheet from the workbook
XSSFSheet sheet = workbook.getSheetAt(0);
// Iterate through each rows one by one
Iterator<Row> rowIterator = sheet.iterator();
Row row = rowIterator.next();
// For each row, iterate through all the columns
// Iterator<Cell> cellIterator = row.cellIterator();
int colNum = 0;
while (rowIterator.hasNext()) {
row = rowIterator.next();
// For each row, iterate through all the columns
Iterator<Cell> cellIterator = row.cellIterator();
// For each row, iterate through all the columns
while (cellIterator.hasNext()) {
Cell cell = cellIterator.next();
// cells.put(headers.get(colNum++), getCharValue(cell).toString());
headers.add(colNum + ((colNum + 1)), getCharValue(cell).toString());
}
parsedFile.add(cells);
++colNum;
}
workbook.close();
} catch (Exception e) {
e.printStackTrace();
}
return parsedFile;
}
共 (0) 个答案