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 ...
随机推荐
- Swift-Dictionary
1.字典写法 Dictionary<KeyType,ValueType>,KeyType是你想要储存的键,ValueType是你想要储存的值. 唯一的限制就是KeyType必须是可哈希的, ...
- 计算任意位数的Pi
当用程序实现求pi的值时,也许你能够很快写出算法(利用求pi的几个公式),但是由于使用单变量保存结果,限于计算机硬件对变量的表示范围有限,因此,最多只能计算出pi值小数点后十多位.但需要得到一个更大位 ...
- [AngularJS] Use ng-model-options to limit $digest
Refer: http://toddmotto.com/super-fast-angular-ng-model-options-limit-digest-cycles/ Use: <input ...
- [Flux] Component / Views
The application will dislay a some catalogs, and each catalog has title image, description. Catalog: ...
- iOS:编译错误Undefined symbols for architecture i386: _OBJC_CLASS_$_XXX", referenced from: error
Undefined symbols for architecture i386: _OBJC_CLASS_$_XXX", referenced from: error 这个意思为无法找到名为 ...
- 黑白图像(DFS)
输入一个n*n的黑白图像(1表示黑色,0表示白色),任务是统计其中八连块的个数.如果两个黑格子有公共边或者公共顶点,就说它们属于同一个八连块.如图6-11所示的图形有3个八连块. 图6-11 拥有3 ...
- java的通信机制
通信机制无非就那几种:http访问.socket访问: http又分为:jsp.servlet.html,用的就是get和post方法 socket则可分为:tcp或者udp方式 从以上内容又衍生出其 ...
- android anim 动画效果(转)
动画效果编程基础--AnimationAndroid 动画类型 Android的animation由四种类型组成 XML中 alpha 渐变透明度动画效果 ...
- 最小圆覆盖 hdu 3007
今天学习了一下最小圆覆盖, 看了一下午都没看懂, 晚上慢慢的摸索这代码,接合着别人的讲解, 画着图跟着代码一步一步的走着,竟然有些理解了. 最小圆覆盖: 给定n个点, 求出半径最小的圆可以把这些点全部 ...
- 初识Ajax技术
Ajax:(Asynchronous JavaScript And Xml)是一种整合了JavaScript.XML.CSS等现有技术 Ajax工作流程: 纯javaScript的Ajax请求 ...