- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
当我单击应用程序的“导出文件”选项时,我想向用户显示“另存为”Windows,该文件是一个 excel 2007,而不是我使用 Apache POI 创建的文件。文件正确保存在文件夹“D:\jboss-6.1.0.Final\bin”中,但不是显示“另存为”窗口,而是重定向到带有奇怪符号和字符的页面。
最奇怪的是我在应用程序的其他页面中有其他按钮用于下载 Excel 文件,并且使用 POI 的相同代码也可以正常显示“另存为”。
为什么会这样???
谢谢。
我附上一张图片。
导出函数的代码是:
public void exportarTabla(){
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet("Hoja 1");
XSSFRow row;
XSSFCell cell;
for (int i = 0; i < getLstEtiquetasCol().size(); i++) {
row = sheet.createRow(i+3);
for (int j = 0; j < getLstEtiquetasCol().get(i).size(); j++) {
cell = row.createCell(j+3+getLstEtiquetasFil().get(0).size());
cell.setCellValue(getLstEtiquetasCol().get(i).get(j).getValor().getEtiqueta());
}
}
for (int i = 0; i < getLstEtiquetasFil().size(); i++) {
row = sheet.createRow( i+3+getLstEtiquetasCol().size());
for (int j = 0; j < getLstEtiquetasFil().get(i).size(); j++) {
cell = row.createCell(j+3);
cell.setCellValue(getLstEtiquetasFil().get(i).get(j).getValor().getEtiqueta());
}
}
for (int i = 0; i < getTableContact().size(); i++) {
row = sheet.getRow( i+3+getLstEtiquetasCol().size());
for (int j = 0; j < getTableContact().get(i).size(); j++) {
cell = row.createCell(j+3+getLstEtiquetasFil().get(0).size());
cell.setCellValue(Double.parseDouble(getTableContact().get(i).get(j).getEtiqueta()));
}
}
try {
this.archivo_salida = "D:/jboss-6.1.0.Final/bin/output2.xlsx";
FileOutputStream fileOut = new FileOutputStream(new File(archivo_salida));
workbook.write(fileOut);
if(fileOut != null){
try{
File ficheroXLS = new File(archivo_salida);
FacesContext ctx = FacesContext.getCurrentInstance();
FileInputStream fis = new FileInputStream(ficheroXLS);
byte[] bytes = new byte[1000];
int read = 0;
if (!ctx.getResponseComplete()) {
String fileName = ficheroXLS.getName();
String contentType = "application/vnd.ms-excel";
//String contentType = "application/pdf";
HttpServletResponse response =(HttpServletResponse) ctx.getExternalContext().getResponse();
response.setContentType(contentType);
response.setHeader("Content-Disposition","attachment;filename=\"" + fileName + "\"");
ServletOutputStream out = response.getOutputStream();
while ((read = fis.read(bytes)) != -1) {
out.write(bytes, 0, read);
}
out.flush();
out.close();
System.out.println("\nDescargado\n");
ctx.responseComplete();
}
}catch(IOException e){
e.printStackTrace();
} finally {
try {
if (fileOut != null) {
fileOut.close();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
WEB.xml
<?xml version="1.0" ?>
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd” 版本=“2.5”>
<!-- RichFaces -->
<context-param>
<param-name>org.richfaces.SKIN</param-name>
<param-value>blueSky</param-value>
</context-param>
<!-- Suppress spurious stylesheets -->
<context-param>
<param-name>org.richfaces.CONTROL_SKINNING</param-name>
<param-value>disable</param-value>
</context-param>
<context-param>
<param-name>org.richfaces.CONTROL_SKINNING_CLASSES</param-name>
<param-value>disable</param-value>
</context-param>
<!-- Change load strategy to DEFAULT to disable sending scripts/styles as
packs -->
<context-param>
<param-name>org.richfaces.LoadStyleStrategy</param-name>
<param-value>ALL</param-value>
</context-param>
<context-param>
<param-name>org.richfaces.LoadScriptStrategy</param-name>
<param-value>ALL</param-value>
</context-param>
<!-- Seam -->
<listener>
<listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
</listener>
<filter>
<filter-name>Seam Filter</filter-name>
<filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
<init-param>
<param-name>maxRequestSize</param-name>
<param-value>1000000</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Seam Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>Seam Resource Servlet</servlet-name>
<servlet-class>org.jboss.seam.servlet.SeamResourceServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Seam Resource Servlet</servlet-name>
<url-pattern>/seam/resource/*</url-pattern>
</servlet-mapping>
<!-- Facelets development mode (disable in production) -->
<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>@debug@</param-value>
</context-param>
<!-- JSF -->
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.seam</url-pattern>
</servlet-mapping>
<security-constraint>
<display-name>Restrict raw XHTML Documents</display-name>
<web-resource-collection>
<web-resource-name>XHTML</web-resource-name>
<url-pattern>*.xhtml</url-pattern>
</web-resource-collection>
<auth-constraint />
</security-constraint>
<persistence-unit-ref>
<persistence-unit-ref-name>demoencuesta06/pu</persistence-unit-ref-name>
<persistence-unit-name>demoencuesta06</persistence-unit-name>
</persistence-unit-ref>
最佳答案
感谢他们的回复,我发现了问题,问题出在 .xhtml 文件中带有 ajax 的按钮中。它是:
<a4j:commandButton id="btnexportar" onclick="this.disabled=true" oncomplete="this.disabled=false; alert('La Exportacion de Datos ha finalizado')"
action="#{dndBean.exportarTabla}"
value="Exportar Datos">
</a4j:commandButton>
我改为:
<h:commandButton id="generarinforme" action="#{dndBean.exportarTabla}"
value="Exportar Datos">
</h:commandButton>
并且奇怪的角色不再出现。现在我必须寻找一种使用 onclick 和 oncomplete 的方法。谢谢!
关于java - 当我从 Java 下载 Excel 文件时不显示 "Save as"窗口,但文件已正确保存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16592390/
我正在从tangowithdjango学习django 。我试图理解 populate_rango.py 的代码。代码是: import os os.environ.setdefault('DJANG
我试图理解Rserve参数--save,-no-save和--vanilla之间的区别。我在文档或任何论坛中都没有看到任何描述这些效果的内容。有谁确切地知道这些是做什么的? 在OSX中,我需要指定其中
我正在使用 CoreData 制作一个基于文档的应用程序。我可以创建一个新文档,编辑该文档,然后保存它。文件已创建并可以打开。打开后,数据会正确加载。但是,一旦进行了初始保存,所有后续保存都不会执行任
下面提出了类似的问题 How to save complete web page 但目前还没有答案。预期的结果是得到很多文件,一些文件来存储图像等。 我使用了以下内容,它会弹出一个窗口说保存文件 va
我们一直在测试一种不同的保存方式。然而,结果并不像我们预期的那样。我们有创建调查的方法,每个调查有多个问题。我们测试了几个案例,它们都以相同的方式提交查询。 @Transactional class
我想了解JAP Repotitoty的详细信息。我创建了一个服务类、实体类和存储库类,如下所示(用 kotlin 编写)并执行了 ItemService#update 方法。 执行 item2Repo
我正在开发我的第一个 Firefox 扩展。我正在尝试将数据保存在浏览器的本地存储中(使用 Window.localStorage 很容易,但我正在关注 official recommandation
这让我很郁闷。我是 C Sharp 的新手,因此需要一些帮助。我的保存/另存为完全是胡说八道。 真的有两个问题: 如何在不弹出保存对话框的情况下保存对现有文件的更改?如果我单击“保存”,它会弹出一个对
我有一个代码可以将 XML 文件保存到我的目录中。它在我的本地主机和我的共享主机中实际上就像一个魅力,但它在我的 Linux VPS 中不起作用。 我总是遇到这个错误: 警告:DOMDocument:
有没有办法在 django 管理站点中同时“另存为”和“保存并添加另一个”? 最佳答案 我不认为按钮引用的 URL 有任何神奇之处,因此您可以通过简单地覆盖每个 http://docs.djangop
创建 playramework 的模型时,我们可以使用 save() 或 _save() 方法。为什么这两种方法在框架中都可用,原因是什么? (在这种情况下,他们做同样的事情 - 将对象保存到数据库)
我见过两个都调用 $save 的代码和 save到 $resource 的 Angular 。 有什么区别,你什么时候使用? 最佳答案 最佳解释===例子 : // by writing '{ id:
根据save bang your head, active record will drive you mad ,在特殊情况下我们应该避免使用 save! 和 rescue 习惯用法。鉴于此,假设模型
我的菜单栏中有两个按钮,其中包含“保存”和“另存为”按钮。但是,我目前拥有它们相同的代码,并且它会按当前方式保存,并提示用户要保存在哪里。我希望保存按钮仅保存而不提示对话框,除非文件尚不存在。 我尝试
我知道 models.Model 和 forms.ModelForm 都包含您可以覆盖的 .save() 方法。我的问题是它们如何以及何时用于保存对象以及以什么顺序。 最佳答案 ModelForm.s
我一直在尝试使用 freeze_graph函数来获取模型+权重/偏差,但在这个过程中,我发现我的初始网络似乎没有任何变量,尽管能够正确分类图像。我的代码如下: #!/usr/bin/python im
尝试使用 gTTS 模块将文本转换为语音并另存为 wav 文件。 我的代码: import gTTS text = "This is my text in the saving folder" tts
我有一个包含大约 50 个字段和两个提交按钮的表单,“保存”和“保存并提交”。如果用户单击“保存”,则插入用户在表格中填写的值。当用户单击“保存并提交”按钮时,它应该更新或插入用户在表单中填写的所有字
我是 Django 新手。我想知道 django 中的 ModelForm 和 Model 如何协同工作?我的意思是 ModelForm.save() 如何自动保存与之关联的模型?它如何从 reque
我有亲子关系: @Entity @Table(name = "user") public final class User { @Id @GeneratedValue(strategy
我是一名优秀的程序员,十分优秀!