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 ...
随机推荐
- Android ViewPager FragmentPagerAdapter
ViewPager 里面放Fragment <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/and ...
- js事件防止冒泡
原文连接:http://www.cnblogs.com/jams742003/archive/2009/08/29/1556187.html 1. 事件目标 如今.事件处理程序中的变量event保存着 ...
- (转)Android中使用ormlite实现持久化(一)--HelloOrmLite
Android中内置了sqlite,但是常用的开发语言java是面向对象的,而数据库是关系型的,二者之间的转化每次都很麻烦(主 要是我对sql语言不熟悉).而Java Web开发中有很多orm框架,但 ...
- 修改tt模板让ADO.NET C# POCO Entity Generator With WCF Support 生成的实体类继承自定义基类
折腾几天记载一下,由于项目实际需要,从edmx生成的实体类能自动继承自定义的基类,这个基类不是从edmx文件中添加的Entityobject. 利用ADO.NET C# POCO Entity Gen ...
- JDK小技巧
鉴于这段时间重新拾起Android,电脑上又是一大堆不同JDK版本的项目.来回切换JDK环境也够折磨人的. 不同版本JDK切换之后,java -version命令仍然显示的是之前的JDK版本,重启电脑 ...
- .net mvc datatables中orderby动态排序
今天在做项目中用datatables的排序来做筛选,不过人比较懒,不想写那么多的关于排序的代码,于是寻思这在度娘上找找,结果不负有心人啊,更感谢贴出此贴的哥们,来源:http://blog.csdn. ...
- 系统spt_values表--生成时间方便left join
时间处理我给你提供一个思路 系统有个spt_values表,可以构造一整个月的日期,然后左连接你统计好的数据,用CTE表构造多次查询 spt_values的超级经典的应用 http://www. ...
- ASP.NET5 静态文件
静态文件,包括HTML文件,CSS文件,图像文件和JavaScript文件,它是一个应用里所包含的资源. 1. 提供静态文件 默认的,静态文件存储在你的webroot目录下面,webroot的路径定义 ...
- Puer是一个可以实时编辑刷新的前端服务器
##Puer是一个可以实时编辑刷新的前端服务器 确保你安装了nodejs(现在还有没nodejs环境的前端? 拖出去喂狗吧) 使用npm全局安装puer命令 npm install puer -g 输 ...
- DontDestroyOnLoad
本文由博主(YinaPan)原创,转载请注明出处:http://www.cnblogs.com/YinaPan/p/Unity_DontDestroyOnLoad.html public stati ...