您的位置:首页 > 其它

POI导出word文档的基本操作

2014-11-21 14:37 381 查看
                        XWPFDocument doc = new XWPFDocument(); //创建对象

                       XWPFParagraph p1 = doc.createParagraph();  

                       p1.setAlignment(ParagraphAlignment.CENTER);

                       p1.setVerticalAlignment(TextAlignment.TOP);

 //创建table
         XWPFTable table = doc.createTable(6, 4);
         //表格属性
         table.setCellMargins(500, 200, 300, 400);
         
         //行数
         List<XWPFTableRow> tRows = table.getRows();
         //第1行
         XWPFTableRow tRow0 = tRows.get(0);
         //列数
         List<XWPFTableCell> tCell0 = tRow0.getTableCells();

  tCell0.get(0).setText("维修单号");  //table 表格赋值

ServletOutputStream  out = null;
String wordName = "维修订单.docx";
response.setContentType("application/x-msdownloadoctet-stream;charset=utf-8");
       response.setHeader("Content-Disposition", "attachment; filename="+ URLEncoder.encode(wordName, "UTF-8"));
       
       out=response.getOutputStream();

doc.write(out);

out.flush();
out.close();       

//生产doc文档 保存
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  poi word 文件下载