Answer the question
In order to leave comments, you need to log in
How to write the received value of an excel file to another excel in java?
It is necessary for me: value of the received exel of a file to write down in new excel a file.
excel:
Problem: Created a new excel does not open, swears that the format is wrong or the file is damaged.
Question: What is wrong with my code? Am I doing the right thing?
the code
@PostMapping("/import")
public void mapReapExcel(@RequestParam("file") MultipartFile reapExcelDataFile) throws IOException {
XSSFWorkbook workbook = new XSSFWorkbook(reapExcelDataFile.getInputStream());
XSSFSheet worksheet = workbook.getSheetAt(0);
// создание самого excel файла в памяти
XSSFWorkbook wb = new XSSFWorkbook();
// создание листа с названием "Просто лист"
XSSFSheet sheet = workbook.createSheet("Просто лист");
Row row = sheet.createRow(0);
row.createCell(0).setCellValue("Дата");
row.createCell(1).setCellValue("ID платежа");
row.createCell(2).setCellValue("Назаначение платежа");
row.createCell(3).setCellValue("Сумма");
// row.createCell(4).setCellValue("Оплата заказа");
FileOutputStream out = new FileOutputStream(new File("C:\\Users\\xxx\\Desktop\\new_list.xlsx"));
for (int i = 1; i < worksheet.getPhysicalNumberOfRows(); i++) {
XSSFRow row2 = worksheet.getRow(i);
row.createCell(0).setCellValue(row2.getCell(0).toString());
row.createCell(1).setCellValue(row2.getCell(1).toString());
row.createCell(2).setCellValue(row2.getCell(2).toString());
row.createCell(3).setCellValue(row2.getCell(3).getNumericCellValue());
// String[] str = row2.getCell(2).getStringCellValue().split("#");
// row.createCell(4).setCellValue(str[1]);
}
out.close();
}
<code>
P.s буду рад любому совету от Вас
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