最近做了个poi导出word的功能

下面是代码:

一个可以参考的例子:

 package com.lzb.crm.web;

 import java.io.FileOutputStream;
import java.math.BigInteger;
import java.util.List; import org.apache.poi.xwpf.usermodel.Borders;
import org.apache.poi.xwpf.usermodel.BreakClear;
import org.apache.poi.xwpf.usermodel.BreakType;
import org.apache.poi.xwpf.usermodel.LineSpacingRule;
import org.apache.poi.xwpf.usermodel.ParagraphAlignment;
import org.apache.poi.xwpf.usermodel.VerticalAlign;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;
import org.apache.poi.xwpf.usermodel.XWPFTable;
import org.apache.poi.xwpf.usermodel.XWPFTableCell;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblPr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblWidth; /**
*
* @author 全力以赴001
*/
public class ExportDocTest { public static void main(String[] args) throws Exception { XWPFDocument doc = new XWPFDocument(); XWPFParagraph title = doc.createParagraph();//设置活动标题
title.setAlignment(ParagraphAlignment.CENTER);
XWPFRun r1 = title.createRun();
r1.setBold(true);
r1.setFontFamily("宋体");
r1.setText("20元优惠劵活动");//活动名称
r1.setFontSize(22); XWPFParagraph actTheme = doc.createParagraph();//设置活动主题
actTheme.setAlignment(ParagraphAlignment.LEFT);
XWPFRun runText1=actTheme.createRun();
runText1.setText("活动主题:20劵优惠劵活动");
runText1.setFontSize(15); XWPFParagraph actType = doc.createParagraph();//设置活动类型
XWPFRun runText2=actType.createRun();
runText2.setText("活动类型:系统发劵类型");
runText2.setFontSize(15); XWPFParagraph actDate = doc.createParagraph();//设置活动日期
XWPFRun actDaterun=actDate.createRun();
actDaterun.setText("活动日期:2015-06-08至2015-06-10");
actDaterun.setFontSize(15); XWPFParagraph actText = doc.createParagraph();//设置活动内容
XWPFRun runText3=actText.createRun();
runText3.setText("活动内容:哈哈哈士大夫士大夫立刻绝对是方路即可大水井坊路可绝对是弗兰克家第三方立刻几点睡了罚款绝对是路客服绝对是路客服绝对是路客服几点睡了罚款家第三方立刻几点睡了罚款记录可定时 ");
runText3.setFontSize(15); XWPFParagraph actRemark = doc.createParagraph();//设置活动备注
XWPFRun runText4=actRemark.createRun();
runText4.setText("活动备注: ");
runText4.setFontSize(15);
runText4.setBold(true);
XWPFRun runText5=actRemark.createRun();
runText5.setText("我是活动备注哦........................ ");
runText5.setFontSize(15); XWPFParagraph actRule = doc.createParagraph();//设置活动备注
XWPFRun rule=actRule.createRun();
rule.setText("活动规则: ");
rule.setFontSize(15);
rule.setBold(true); XWPFTable table=actRule.getDocument().createTable(2,2);//创建表格
table.setWidth(500);
table.setCellMargins(20, 20, 20, 20);
System.out.println(table.getWidth()); //表格属性
CTTblPr tablePr = table.getCTTbl().addNewTblPr();
//表格宽度
CTTblWidth width = tablePr.addNewTblW();
width.setW(BigInteger.valueOf(8000)); List<XWPFTableCell> tableCells = table.getRow(0).getTableCells();
tableCells.get(0).setText("第一行第一列的数据:规则类型名称");
tableCells.get(1).setText("第一行第二列的数据:规则描述"); List<XWPFTableCell> tableCellsq = table.getRow(1).getTableCells();
tableCellsq.get(0).setText("第二行第一列的数据:A发劵规则");
tableCellsq.get(1).setText("第二行第二列的数据:A发劵规则针对5星级用户"); XWPFParagraph text3 = doc.createParagraph();
XWPFRun runText7=text3.createRun();
runText7.setText("负责人:zhangsan");
runText7.setFontSize(15); XWPFParagraph text8 = doc.createParagraph();
XWPFRun runText8=text8.createRun();
runText8.setText("负责人电话:12345678921");
runText8.setFontSize(15); FileOutputStream out = new FileOutputStream("C:\\User\\Desktop\\test.docx"); doc.write(out);
System.out.println(1);
out.close(); }
}

poi导出word的更多相关文章

  1. java工具类POI导出word

    1.新建一个word,里面填写内容,如: 2.导出wordjava类 /** * POI导出word测试 * @throws Exception */ @RequestMapping(value=&q ...

  2. poi导出word表格详解 超详细了

    转:非常感谢原作者 poi导出word表格详解 2018年07月20日 10:41:33 Z丶royAl 阅读数:36138   一.效果如下 二.js代码 function export_word( ...

  3. poi导出word时设置兼容性

    接上一篇poi导出word http://www.cnblogs.com/xiufengd/p/4708680.html. public static void setAuto(XWPFDocumen ...

  4. 使用POI导出Word(含表格)的实现方式及操作Word的工具类

    .personSunflowerP { background: rgba(51, 153, 0, 0.66); border-bottom: 1px solid rgba(0, 102, 0, 1); ...

  5. Spring MVC中使用POI导出Word

    内容绝大部分来源于网络 准备工作 准备[XwpfTUtil]工具类(来源于网络) 准备word模版 下载[XwpfTUtil]工具类 import org.apache.poi.xwpf.usermo ...

  6. POI导出Word插入复选框

    POI功能比较强大,但是有些不常用功能比如插入特殊符号,不知道API怎么调用 Word里要插入复选框,首先想到的是POI有没有提供现成的API,搜了一番,貌似都说不直接支持 http://stacko ...

  7. poi导出word模板项目实例(一个文件)

    在页面上填写值,然后导出到word模板中,并把页面上的值带到模板中,也就是导出word文档,提前有word 的模板形式, 1.jsp 页面   <table class="formTa ...

  8. poi导出word表格跨行

    DataCommon.java package com.ksource.pwlp.model.statistic; public class DataCommon { private Long id; ...

  9. poi导出word文档,doc和docx

    maven <!-- https://mvnrepository.com/artifact/org.apache.poi/poi --><dependency> <gro ...

随机推荐

  1. Android ViewPager PagerAdapter 图片轮播

    ViewPager类直接继承了ViewGroup类,所有它是一个容器类,可以在其中添加其他的View类. ViewPager类需要一个PagerAdapter适配器类给它提供数据. ViewPager ...

  2. RT: TCP REUSEADDR or REUSEPORT

    Welcome to the wonderful world of portability... or rather the lack of it. Before we start analyzing ...

  3. GDB调试技巧

    1. 查看内存分布 (gdb) info proc mappings 2. 对于类的调试,先通过行号来设断点, 比如:(gdb) b TcpConnection.cc:63 3. 打印数组的内容 (g ...

  4. 使用jQuery Mobile和Phone Gap开发Android应用程序(转)

    经过了一段时间的学习,初步了解了该如何使用jQuery Mobile和 Phone Gap来开发一个Android应用程序,也想把这些东西介绍给大家. 1. 软件准备 要进行android app的开 ...

  5. 【开源java游戏框架libgdx专题】-09-动画的使用

    1.Animation类介绍   Api定义:动画是由多个帧,在设定的时间间隔序列显示.比如,一个跑步的人一个动画可以通过运行时播放这些图像无限拍照他了. 功能用法:管理动画,设置随即播放模式和播放顺 ...

  6. 大牛对ACM入门菜鸟的一些话

    首先就是我为什么要写这么一篇日志.原因很简单,就是因为前几天有个想起步做ACM人很诚恳的问我该如何入门.其实就现在而言,我并不是很想和人再去讨论这样的话题,特别是当我发现我有很多的东西要学的时候,我实 ...

  7. Pgsql 里面 COALESCE的用法

    有这种要求,更新自己本身的字段的某个值进行加或者减, 常规方法: UPDATE tbl_kintai_print_his SET print_time = now(), print_emp_cd = ...

  8. Linux下安装php加速组件XCache

    这里选择的是稳定版本的1.2.2版本,2.0版本的不稳定.wget http://xcache.lighttpd.net/pub/Releases/1.2.2/xcache-1.2.2.tar.gzt ...

  9. xmpp发送文件

    xmpp 文件传输协议: XEP-0096: SI File Transfer:文件传输流初始化协议 XEP-0065: SOCKS5 Bytestreams:带外socks5代理字节流传输协议 XE ...

  10. 关于模板中的动态取值 ---反射与javascript脚本编译

    在项目中经常遇到一个问题,打印word或者打印excel的时候,我们经常使用一对一的赋值或者批量替换的方式来对模板进行修改. 但是现在遇到两种场景: 1.取值是通过自定以方法进行取值的. 如:一个销售 ...