poi中创建.docx文档

pom包

<dependency>
	<groupId>org.apache.poi</groupId>
	<artifactId>poi</artifactId>
	<version>4.0.0</version>
</dependency>
<dependency>
	<groupId>org.apache.poi</groupId>
	<artifactId>poi-ooxml</artifactId>
	<version>4.0.0</version>
</dependency>
<dependency>
	<groupId>org.apache.poi</groupId>
	<artifactId>poi-scratchpad</artifactId>
	<version>4.0.0</version>
</dependency>
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("1、活动主题:20劵优惠劵活动");
        runText1.setFontSize(13);

        XWPFParagraph actType = doc.createParagraph();//设置活动类型
        XWPFRun runText2=actType.createRun();
        runText2.setText("2、活动类型:系统发劵类型");
        runText2.setFontSize(13);

        XWPFParagraph actDate = doc.createParagraph();//设置活动日期
        XWPFRun actDaterun=actDate.createRun();
        actDaterun.setText("3、活动日期:2015-06-08至2015-06-10");
        actDaterun.setFontSize(13);

        XWPFParagraph actText = doc.createParagraph();//设置活动内容
        XWPFRun runText3=actText.createRun();
        runText3.setFontSize(13);
        runText3.setText("4、活动内容:哈哈哈士大夫士大夫立刻绝对是方路即可大水井坊路可绝对是弗兰克家第三方立刻几点睡了罚款绝对是路客服绝对是路客服绝对是路客服几点睡了罚款家第三方立刻几点睡了罚款记录可定时 ");

        XWPFParagraph actRemark = doc.createParagraph();//设置活动备注
        XWPFRun runText4=actRemark.createRun();
        runText4.setText("5、活动备注: ");
        runText4.setFontSize(13);
        runText4.setBold(true);
        XWPFRun runText5=actRemark.createRun();
        runText5.setText("我是活动备注哦........................ ");
        runText5.setFontSize(12);

        XWPFParagraph actRule = doc.createParagraph();//设置活动备注
        XWPFRun rule=actRule.createRun();
        rule.setText("6、活动规则: ");
        rule.setFontSize(13);
        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 text9 = doc.createParagraph();
        XWPFRun runText9=text9.createRun();
        runText9.addBreak(BreakType.TEXT_WRAPPING);//换行
        runText9.setBold(true);
        runText9.setText("7、请现在你喜欢运动?");
        runText9.setFontSize(13);

        XWPFParagraph text10 = doc.createParagraph();
        XWPFRun runText10=text10.createRun();
        runText10.setFontSize(12);
        runText10.setText("□a.排球       ");
        runText10.setText("☑b.羽毛球");


        XWPFParagraph text3 = doc.createParagraph();
        XWPFRun runText7=text3.createRun();
        runText7.setText("负责人:zhangsan");
        runText7.setFontSize(13);

        XWPFParagraph text8 = doc.createParagraph();
        XWPFRun runText8=text8.createRun();
        runText8.setText("负责人电话:12345678921");
        runText8.setFontSize(13);


        FileOutputStream out = new FileOutputStream("E:\\test.docx");

        doc.write(out);
        out.close();
来做第一个评论吧!~

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇