java excel 另存为_当我从Java下载Excel文件不显示“另存为”窗口,但文件被正确保存...

最奇怪的是我有其他按钮用于下载我的应用程序的其他页面中的excel文件,并且与POI同样的代码y也一样,“另存为”通常出现。

为什么发生?

谢谢。

我附上一张图片。

53a1df0ef8a33b155803ad58e623624a.png

函数导出的代码是: 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值