日期:2014-05-18  浏览次数:20761 次

为什么在有的电脑上jsp导不出excel?
为什么在有的电脑上jsp导不出excel?
没有弹出保存窗口
<%
String   out_xls=(String)request.getAttribute( "out_xls ");
int   a=out_xls.lastIndexOf( "\\ ");
String   filename   =out_xls.substring(a+1);
String   filepath   =   out_xls.substring(0,a+1);

//   设置响应头和下载保存的文件名
response.setContentType( "application/vnd.ms-excel ");

response.setHeader( "Content-Disposition ",
"attachment;   filename=\ " "   +   filename   +   "\ " ");

//   打开指定文件的流信息
java.io.FileInputStream   fileInputStream   =
new   java.io.FileInputStream(filepath   +   filename);

//   写出流信息
int   i;
while   ((i=fileInputStream.read())   !=   -1)   {
out.write(i);
}
fileInputStream.close();
out.close();
%>

------解决方案--------------------
可能是客户端没有安装Excel
------解决方案--------------------
可能跟jdk的版本和操作系统有关系

------解决方案--------------------
查看Excel的版本是否相同。我以前也遇见过这样问题,是因为Excel版本不同。
------解决方案--------------------
客户端有安装Excel

------解决方案--------------------
一直用jxl
request.setCharacterEncoding( "GBK ");
boolean bExportSucc = false;
String sErrorStr= " ";
String sHead= " ";
String sFileName= "( "+request.getParameter( "time1 ")+request.getParameter( "time2 ")+ ").xls ";
String sCurrPath=application.getRealPath(sHead);
if(!sCurrPath.substring(sCurrPath.length()-1).equals( "/ "))sCurrPath=sCurrPath+ "/ ";
sCurrPath=sCurrPath+sFileName;

//获取文件的URL地址
String sAttachServer= "127.0.0.1 ";
if(sAttachServer.length()==0)
sAttachServer=request.getServerName()+ ": "+request.getServerPort();
String sUrlPath= "http:// "+sAttachServer+sHead+sFileName;
File file=new File(sCurrPath);

//以下开始输出到EXCEL
try {
/************创建工作簿*************/
WritableWorkbook workbook = Workbook.createWorkbook(file);
/************创建工作表*************/
WritableSheet sheet = workbook.createSheet( "财务出粮表( "+request.getParameter( "time1 ")+request.getParameter( "time2 ")+ ") ", 0);
/************设置页眉、页脚******************/
sheet.setHeader( "页眉 ", " ", "第 &P 页,共 &N 页 "); //设置页眉
sheet.setFooter( " ", " ", "&D &T "); //设置页脚
/******注:以上这些&P、&D等参数可以从EXCEL的宏录制取得********/



/***********设置列宽*****************/
sheet.setColumnView(0,5); //第1列
sheet.setColumnView(1,10); //第2列
sheet.setColumnView(2,10);
sheet.setColumnView(3,10);
/**************设置单元格字体***************/
WritableFont NormalFont = new WritableFont(WritableFont.TIMES,10);
WritableFont BoldFont = new WritableFont(WritableFont.TIMES,14,WritableFont.BOLD);

/**************以下设置几种格式的单元格*************/
//用于标题
WritableCellFormat wcf_title = new WritableCellFormat(BoldFont);
wcf_title.setBorder(Border.NONE, BorderLineStyle.THIN); //线条