首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

java 经过使用itext 生成2003 word 文档(java生成word文档2)

2012-09-09 
java 通过使用itext 生成2003 word 文档(java生成word文档2)public static RtfWriter2 getDoc() throws Ex

java 通过使用itext 生成2003 word 文档(java生成word文档2)

public static RtfWriter2 getDoc() throws Exception {// 设置纸张大小Document document = new Document(PageSize.A4);// 建立一个书写器(Writer)与document对象关联,通过书写器(Writer)可以将文档写入到磁盘中RtfWriter2 writer = RtfWriter2.getInstance(document,new FileOutputStream(new File("d:\\hello.doc")));document.open();// 设置中文字体BaseFont bfChinese = BaseFont.createFont("STSongStd-Light","UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);// 标题字体风格Font titleFont = new Font(bfChinese, 12, Font.BOLD);// 正文字体风格Font contextFont = new Font(bfChinese, 10, Font.NORMAL);Font parTitle = new Font(bfChinese, 10, Font.BOLD);Paragraph title = new Paragraph("标题");// 设置标题格式对齐方式title.setAlignment(Element.ALIGN_CENTER);title.setFont(titleFont);document.add(title);Paragraph paragraph = new Paragraph();paragraph.setAlignment(Element.ALIGN_LEFT);paragraph.setFirstLineIndent(20);Chunk chunk1 = new Chunk("这是一句话");chunk1.setFont(parTitle);paragraph.add(chunk1);Chunk chunk = new Chunk();chunk.append("这是另一句话这是另一句话这是另一句话这是另一句话这是另一句话这是另一句话这是另一句话这是另一句话这是另一句话这是另一句话这是另一句话");chunk.setFont(contextFont);paragraph.add(chunk);document.add(paragraph);Paragraph paragraph2 = new Paragraph("很正常很正常很正常很正常很正常很正常很正常很正常很正常");paragraph2.setAlignment(Element.ALIGN_LEFT);paragraph2.setFirstLineIndent(20);document.add(paragraph2);document.close();return writer;}
?所需jar包在下面

热点排行