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 ...
随机推荐
- [转] Linux TCP/IP网络小课堂:net-tools与iproute2大比较
PS:netstat选项是-planet,方便记忆 http://os.51cto.com/art/201409/450886.htm 如今许多系统管理员仍结合使用ifconfig.route.arp ...
- checkbox 删除
先创建del.php文件: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http ...
- htm5 user-scalable 的意思
<meta name="viewport" content="width=device-width,user-scalable=yes,minimum-scale= ...
- HTML5 ArrayBuffer:类型化数组 (二)
类型化数组是JavaScript操作二进制数据的一个接口. 这要从WebGL项目的诞生说起,所谓WebGL,就是指浏览器与显卡之间的通信接口,为了满足JavaScript与显卡之间大量的.实时的数据交 ...
- UILabel,UITextField,UIButton三大基础控件总结
(一)UILabel空件 属性: 1.背景颜色 label.backgroundColor = [UIColor ***]; 2. 显示文字: label.text = @"******&q ...
- Web学习资源及手册查询整理
入门了解html.css.js.jQuery:http://www.w3school.com.cn/, bootstrap.nodejs.php.jQuery入门:http://www.runoob. ...
- linux网络编程常用头文件
sys/types.h:数据类型定义 sys/socket.h:提供socket函数及数据结构 netinet/in.h:定义数据结构sockaddr_in arpa/inet.h:提供IP地址转换函 ...
- Log4j实现对Java日志的配置全攻略
1. 配置文件 Log4J配置文件的基本格式如下: #配置根Logger log4j.rootLogger = [ level ] , appenderName1 , appenderName2 , ...
- Adb shell 常用命令
1. 查看IP adb shell netcfg 2. 查看挂载设备 adb devices 3. 将本地端口转发至手机端口 adb forward tcp: tcp: // PC上所有6100端口通 ...
- Android学习----打印日志Log
Log.v(tag,msg);所有内容 Log.d(tag,msg);debug Log.i(tag,msg);一般信息 Log.w(tag,msg);警告信息 Log.e(tag,msg);错误信息 ...