以下是关键部分代码
ByteArrayOutputStream bout = new ByteArrayOutputStream();
wb.write(bout);
bout.flush();
ByteArrayInputStream Workbookinput = new ByteArrayInputStream(bout.toByteArray());
POIFSFileSystem fs = null;
FileOutputStream fos= null;
try {
fs = new POIFSFileSystem(Workbookinput);
HSSFWorkbook wbbook = new HSSFWorkbook(fs);
Biff8EncryptionKey.setCurrentUserPassword("ouma");
wbbook.writeProtectWorkbook(Biff8EncryptionKey.getCurrentUserPassword(),"admin");
// wb.unwriteProtectWorkbook();
String nrString =ksmc+"模板导出";
response.setHeader("Content-disposition", "attachment;filename="+new
String(nrString.getBytes("gb2312"), "ISO8859-1") + ".xls");
OutputStream ouputStream = response.getOutputStream();
wbbook.write(ouputStream);
ouputStream.flush();
ouputStream.close();
} catch (IOException e) {
e.printStackTrace();
}