0

Good afternoon. I need to make sure that when a button is clicked, a new Excel file is created. I already have this function and everything works, but .. The path and file name are written IN the function itself, and I need to make sure that the path and file name are chosen by the user. How to do it?

<input type="file"> only allows you to select from existing files. And I need to get exactly the path and name for the NEW file.

My function

   @SneakyThrows
    @GetMapping("/Exel")
    @ResponseBody
    public void updateNotFullPay(){
        Integer year = 2022;
        List<DescriptionMotion> description = descriptionMotionService.findMoveByAllBranchAndYear(year);
    
        String file = "C:\\Users\\Elina-AA-int\\exe.xlsx";
        XSSFWorkbook book = new XSSFWorkbook();
        XSSFSheet sheet = book.createSheet("ОК (ООТиЗ)");
.......
//code//
}

My input and link with which I don't know what to do

<input type="file">
<a type="button" class="btn btn-primary btn-sm" th:href="@{/report/Exel}">Создать Exel-файл за текущий год</a>
Shoroh
  • 3
  • 3

1 Answers1

0

You can have the folder path from the <input type="file">, and have the user write the new file-name inside another input: <input type="text">, then pass the both strings to your backend mapping.

You can check the below to see how to select folder instead of file for the tag : Select folder instead of single file - input

  • If I use the method from the link, I can't get the correct path. My values ​​are written С:\fakepath\test.txt instead of the real path. You cannot select an empty directory. And in the files there is a relative path from this folder. – Shoroh Mar 15 '22 at 05:11
  • Oh I see, this might be due to security reasons in the browser, but the webkitdirectory="true" must solve the folder selection. Maybe your fastest solution would be for the user to provide the path as text, and when saving you validate that the path is valid. – Bachir Chahine Mar 15 '22 at 11:51