java下载 字符串整成的word 文档
来源:互联网 发布:去哪里下载ubuntu 编辑:程序博客网 时间:2024/05/21 09:20
public String downloadCompanyInfo() throws Exception{
String fName="导入单位信息";
//用来处理文件名在IE、火狐下载时乱码的现象
if(request.getHeader("user-agent").indexOf("MSIE") != -1) {
fName = java.net.URLEncoder.encode(fName,"utf-8") + ".doc";
} else {
fName = new String(fName.getBytes("utf-8"),"iso-8859-1") + ".doc";
}
//设置输出的格式
response.reset();
response.setContentType("application/x-msdownload");
response.setHeader("Content-Disposition", "attachment; filename=" + fName);
OutputStream out = null;
ByteArrayInputStream bais = null;
try {
String content = StrTable; //就是表格字符串 <table><tr><td>数据</td></tr></table> 这个东西我用的时候是用来做导入excel的时候把错如信息生成一个table字符串输出到word中 当用户点击下载信息的时候,把word下载下来。
byte b[] = content.getBytes();
bais = new ByteArrayInputStream(b);
POIFSFileSystem poifs = new POIFSFileSystem();
DirectoryEntry directory = poifs.getRoot();
DocumentEntry documentEntry = directory.createDocument("WordDocument", bais);
out = response.getOutputStream();
poifs.writeFilesystem(out);
bais.close();
response.flushBuffer();
} catch (Exception e) {
e.printStackTrace();
} finally {
StrTable=""; //把表格清空
try {
if(out != null){
out.close();
}
if(bais != null){
bais.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
String fName="导入单位信息";
//用来处理文件名在IE、火狐下载时乱码的现象
if(request.getHeader("user-agent").indexOf("MSIE") != -1) {
fName = java.net.URLEncoder.encode(fName,"utf-8") + ".doc";
} else {
fName = new String(fName.getBytes("utf-8"),"iso-8859-1") + ".doc";
}
//设置输出的格式
response.reset();
response.setContentType("application/x-msdownload");
response.setHeader("Content-Disposition", "attachment; filename=" + fName);
OutputStream out = null;
ByteArrayInputStream bais = null;
try {
String content = StrTable; //就是表格字符串 <table><tr><td>数据</td></tr></table> 这个东西我用的时候是用来做导入excel的时候把错如信息生成一个table字符串输出到word中 当用户点击下载信息的时候,把word下载下来。
byte b[] = content.getBytes();
bais = new ByteArrayInputStream(b);
POIFSFileSystem poifs = new POIFSFileSystem();
DirectoryEntry directory = poifs.getRoot();
DocumentEntry documentEntry = directory.createDocument("WordDocument", bais);
out = response.getOutputStream();
poifs.writeFilesystem(out);
bais.close();
response.flushBuffer();
} catch (Exception e) {
e.printStackTrace();
} finally {
StrTable=""; //把表格清空
try {
if(out != null){
out.close();
}
if(bais != null){
bais.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
0 0
- java下载 字符串整成的word 文档
- Java之下载word文档
- 下载Word文档的四种方法
- 下载word文档
- java后台利用模板生成Word文档提供前台下载
- 【Java】使用模板生成word文档到服务器,并下载
- java实现的导出word文档
- java 导出word格式的文档
- POI应用:利用word模板批量生成word文档(java中word文档的读写)
- JSP实现word文档的上传,在线预览,下载
- freemarker下载word文档功能的实现以及注意点
- java操作word文档
- java制作word文档
- java解析word文档
- JAVA操作WORD文档
- java操作word文档
- java 导出word文档
- Java导出Word文档
- 有一种状态,叫 隐身可见!有一种感情,叫 自作多情!
- EBS开发——Form开发积累的常用代码
- CSAPP 书附带的代码中找不到的 config.h 在此给出(坑爹啊。。。)
- Oracle Goldengate添加同步对象到已有的同步队列
- 用JS实现按回车键提交表单----------工作问题005
- java下载 字符串整成的word 文档
- 在iOS中创建静态库
- 操作简便的JPG图片转为PDF转换器
- Oracle EBS Form开发小技巧汇总
- 统计git提交次数
- HDU1869 六度分离 【Floyd】
- Android WifiDisplay分析二:Wifi display连接过程
- Linux查看某目录占用空间以及其下有多少个文件
- C#中异步调用