Java创建多个Excel文件
如何创建多个Excel文件并打开供用户下载。我正在将下一个代码用于一个,如果我再次这样做,一个又一个又一个excrels,但两者都是创建第二个。
创建第一个Excel代码
GotrPersClass gotrPersClas = ...;
try {
FileResource res;
res = ReportTakeAway.generateCustomExcel1(gotrPersClas, office, dateF, dateT);
if (res != null) {
setResource("dlexcel", res);
ResourceReference rr = ResourceReference.create(res, this, "dlexcel");
getUI().getPage().open(rr.getURL(), "_blank", false);
}
}
catch (Exception e) {
}
以创建第二个Excel的
List<Map<String, Object>> rs = ...;
try {
FileResource resClass;
resClass = ReportTakeAway.generateCustomExcel2(rs, office, dateF, dateT);
if (resClass != null) {
setResource("dlexcel", resClass);
ResourceReference rr = ResourceReference.create(resClass, this, "dlexcel");
getUI().getPage().open(rr.getURL(), "_blank", false);
}
}
catch (Exception e) {
}
代码是一个接一个地
找到的一个此链接,但不适合Java:
How to create multiple excel files and open for user to download. I am using next code for one, if I do it again , one after the other, I get two excels, but both are the one that is created second.
code to create first excel
GotrPersClass gotrPersClas = ...;
try {
FileResource res;
res = ReportTakeAway.generateCustomExcel1(gotrPersClas, office, dateF, dateT);
if (res != null) {
setResource("dlexcel", res);
ResourceReference rr = ResourceReference.create(res, this, "dlexcel");
getUI().getPage().open(rr.getURL(), "_blank", false);
}
}
catch (Exception e) {
}
code to create second excel
List<Map<String, Object>> rs = ...;
try {
FileResource resClass;
resClass = ReportTakeAway.generateCustomExcel2(rs, office, dateF, dateT);
if (resClass != null) {
setResource("dlexcel", resClass);
ResourceReference rr = ResourceReference.create(resClass, this, "dlexcel");
getUI().getPage().open(rr.getURL(), "_blank", false);
}
}
catch (Exception e) {
}
both codes are one after another
found this link, but is not for java:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为问题在于
在这两种情况下为客户端(浏览器)创建引用的行。
因此,无论用户选择哪个下载,引用为“dlexel”的文件都只会提供两者之一。
https://vaadin.com/api/framework/7.7.30/com/vaadin/server/ResourceReference.html#ResourceReference-com.vaadin.server.Resource-com.vaadin.server.ClientConnector-java.lang .String-
尝试为参数“key”设置唯一值。
I believe the problem is in the lines
which create the reference for the client (browser) in both cases.
So regardless which download the user chooses, the file referenced as 'dlexel' will only provide one of the two.
https://vaadin.com/api/framework/7.7.30/com/vaadin/server/ResourceReference.html#ResourceReference-com.vaadin.server.Resource-com.vaadin.server.ClientConnector-java.lang.String-
Try to have unique values for the parameter 'key'.