如何获取新文件的名称和路径
下午好。我需要确保单击按钮时会创建一个新的 Excel 文件。我已经有了这个函数并且一切正常,但是..路径和文件名写在函数本身中,我需要确保路径和文件名是由用户选择的。怎么做呢?
仅允许您从现有文件中进行选择。我需要准确获取新文件的路径和名称。
我的功能
@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//
}
我的输入和链接我不知道该怎么做
<input type="file">
<a type="button" class="btn btn-primary btn-sm" th:href="@{/report/Exel}">Создать Exel-файл за текущий год</a>
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以从
获取文件夹路径,并让用户在另一个输入中写入新文件名:
,然后将这两个字符串传递到后端映射。
您可以检查以下内容以了解如何为标签选择文件夹而不是文件: 选择文件夹而不是单个文件 - 输入
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