poi导出word
最近做了个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的更多相关文章
- java工具类POI导出word
1.新建一个word,里面填写内容,如: 2.导出wordjava类 /** * POI导出word测试 * @throws Exception */ @RequestMapping(value=&q ...
- poi导出word表格详解 超详细了
转:非常感谢原作者 poi导出word表格详解 2018年07月20日 10:41:33 Z丶royAl 阅读数:36138 一.效果如下 二.js代码 function export_word( ...
- poi导出word时设置兼容性
接上一篇poi导出word http://www.cnblogs.com/xiufengd/p/4708680.html. public static void setAuto(XWPFDocumen ...
- 使用POI导出Word(含表格)的实现方式及操作Word的工具类
.personSunflowerP { background: rgba(51, 153, 0, 0.66); border-bottom: 1px solid rgba(0, 102, 0, 1); ...
- Spring MVC中使用POI导出Word
内容绝大部分来源于网络 准备工作 准备[XwpfTUtil]工具类(来源于网络) 准备word模版 下载[XwpfTUtil]工具类 import org.apache.poi.xwpf.usermo ...
- POI导出Word插入复选框
POI功能比较强大,但是有些不常用功能比如插入特殊符号,不知道API怎么调用 Word里要插入复选框,首先想到的是POI有没有提供现成的API,搜了一番,貌似都说不直接支持 http://stacko ...
- poi导出word模板项目实例(一个文件)
在页面上填写值,然后导出到word模板中,并把页面上的值带到模板中,也就是导出word文档,提前有word 的模板形式, 1.jsp 页面 <table class="formTa ...
- poi导出word表格跨行
DataCommon.java package com.ksource.pwlp.model.statistic; public class DataCommon { private Long id; ...
- poi导出word文档,doc和docx
maven <!-- https://mvnrepository.com/artifact/org.apache.poi/poi --><dependency> <gro ...
随机推荐
- Deme_遥感控制物体移动(涉及遮罩,小摄像机跟随)
using UnityEngine; using System.Collections; using UnityEngine.EventSystems; public class JoyControl ...
- 完整的站内搜索Demo(Lucene.Net+盘古分词)
前言 首先自问自答几个问题,以让各位看官了解写此文的目的 什么是站内搜索?与一般搜索的区别? 很多网站都有搜索功能,很多都是用SQL语句的Like实现的,但是Like无法做到模糊匹配(例如我搜索“.n ...
- Sublime 注册码
----- BEGIN LICENSE ----- Andrew Weber Single User License EA7E-855605 813A03DD 5E4AD9E6 6C0EEB94 BC ...
- 使用easy_install安装numpy、pandas、matplotlib及各种第三方模块
倒腾了一晚上最终把题目中的环境配好了.以下简要说明.留作资料.并共享. 1.安装python. 在cmd中能进入python环境,通过把python路径加入到系统路径中就可以实现. 2.安装easy- ...
- 一个站点的诞生06-- ORM
站点上的数据,存在数据库里. 一般用Mysql,也实用sqlite,Postgre.操作数据库要会SQL语言,这个有点麻烦,经常须要查手冊. 此外.每家数据库在实现SQL语言的时候,经常会加料,添加一 ...
- 改写URL的查询字符串QUERY_STRING(转)
查询字符串是指URL请求中“问号”后面的部分.比如,http://www.nowamagic.net/?foo=bar中粗体部分就是查询字符串,其中变量名是foo,值是bar. 1. 利用QSA转换查 ...
- cogs 53 多人背包
/* 要求每个最优 即累加前k优解 注意不用去重 */ #include<iostream> #include<cstdio> #include<cstring> ...
- MySql Connector/Net Mysql like 搜索中文的问题(c#和asp.net连接mysql)
Connector/Net 6.9.8 选择.net/mono即可,不需要安装. 将对应版本的MySql.Data.dll复制到bin目录下即可使用 http://dev.mysql.com/down ...
- cas sso单点登录系列1_cas-client Filter源码解码(转)
转:http://blog.csdn.net/ae6623/article/details/8841801?utm_source=tuicool&utm_medium=referral /* ...
- poj3278 BFS入门
M - 搜索 Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:65536KB 64bit I ...