最奇怪的是我有其他按钮用于下载我的应用程序的其他页面中的excel文件,并且与POI同样的代码y也一样,“另存为”通常出现。
为什么发生?
谢谢。
我附上一张图片。
函数导出的代码是: 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”>
org.richfaces.SKIN
blueSky
org.richfaces.CONTROL_SKINNING
disable
org.richfaces.CONTROL_SKINNING_CLASSES
disable
org.richfaces.LoadStyleStrategy
ALL
org.richfaces.LoadScriptStrategy
ALL
org.jboss.seam.servlet.SeamListener
Seam Filter
org.jboss.seam.servlet.SeamFilter
maxRequestSize
1000000
Seam Filter
/*
Seam Resource Servlet
org.jboss.seam.servlet.SeamResourceServlet
Seam Resource Servlet
/seam/resource/*
facelets.DEVELOPMENT
@[email protected]
javax.faces.DEFAULT_SUFFIX
.xhtml
Faces Servlet
javax.faces.webapp.FacesServlet
1
Faces Servlet
*.seam
Restrict raw XHTML Documents
XHTML
*.xhtml
demoencuesta06/pu
demoencuesta06