java html 转word_Java Html转Word

public void createDocContext(HttpServletRequest request,

HttpServletResponse response) throws DocumentException, IOException {

String info = request.getParameter("infoTxt");

// 处理中文乱码

if (info != null) {

info = new String(info.getBytes("iso8859-1"), "UTF-8");

}

// 生成导出文件的文件名

String filePath = "QrySaleMainTestFileMS" + ".doc";

response.setHeader("Content-disposition", "attachment;filename="

+ filePath);

response.setContentType("application/vnd.ms-excel");

OutputStream out = response.getOutputStream();

//POI导出Word

// String content = "" + "

你好" + "" + "

// + "

" + "信息1" + "信息2" + "t3"

// + "

" + "" + "" + "";

//

// byte b[] = content.getBytes();

byte b[] = info.getBytes();

ByteArrayInputStream bais = new ByteArrayInputStream(b);

POIFSFileSystem poifs = new POIFSFileSystem();

DirectoryEntry directory = poifs.getRoot();

DocumentEntry documentEntry = directory.createDocument("WordDocument",

bais);

poifs.writeFilesystem(out);

bais.close();

out.close();

// itext导出word

// // 设置纸张大小

// Document document = new Document(PageSize.A4);

//

// // 建立一个书写器(Writer)与document对象关联,通过书写器(Writer)可以将文档写入到磁盘中

// RtfWriter2.getInstance(document, response.getOutputStream());

//

// document.open();

//

// // 设置中文字体

// BaseFont bfChinese = BaseFont.createFont("STSongStd-Light",

// "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);

//

// // 标题字体风格

// Font titleFont = new Font(bfChinese, 12, Font.BOLD);

//

// // 正文字体风格

// Font contextFont = new Font(bfChinese, 10, Font.NORMAL);

//

// Paragraph title = new Paragraph("主套餐评估报告");

//

// // 设置标题格式对齐方式

// title.setAlignment(Element.ALIGN_CENTER);

//

// // title.setFont(titleFont);

//

// document.add(title);

//

// Paragraph context = new Paragraph(info);

//

// // 正文格式左对齐

// context.setAlignment(Element.ALIGN_LEFT);

//

// // context.setFont(contextFont);

//

// // 离上一段落(标题)空的行数

// context.setSpacingBefore(5);

//

// // 设置第一行空的列数

// context.setFirstLineIndent(20);

//

// document.add(context);

//

// document.close();

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值