您好,欢迎光临本网站![请登录][注册会员]  
文件名称: itext导出word文件
  所属分类: Web开发
  开发工具:
  文件大小: 1mb
  下载次数: 0
  上传时间: 2011-03-20
  提 供 者: zhang******
 详细说明: import java.awt.Color; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import com.lowagie.text.Cell; import com.lowagie.text.Document; import com.lowagie.text.DocumentException; import com.lowagie.text.Font; import com.lowagie.text.PageSize; import com.lowagie.text.Paragraph; import com.lowagie.text.Table; import com.lowagie.text.pdf.BaseFont; import com.lowagie.text.rtf.RtfWriter2; public class GenWordSample { private static final String TARGET_FILE_NAME = "d:\\testWor d.doc"; public static void main(String[] args) { //创建word文档,并设置纸张大小 Document document = new Document(PageSize.A4); try { RtfWriter2.getInstance(document, new FileOutputStream(TARGET_FILE_NAME)); document.open(); //document.setPageSize(new Rectangle(20,30,40,50)); //设置合同头 String contractTitle = "关于申请授权签署2010年度第三批科技类合同事项的请示"; Font newFont = new Font(Font.NORMAL,22,Font.NORMAL, new Color(0,0,0)); Paragraph p = new Paragraph(contractTitle, newFont); p.setAlignment(Table.ALIGN_CENTER); p.setIndentationLeft(60); p.setIndentationRight(60); p.setSpacingBefore(20); //中文字体三种选择 //1.设置中文字体 应该需要(iText-Asian.jar) BaseFont cnFont = BaseFont.createFont("STSongStd-Light", "UniGB-UCS2-H" ,BaseFont.NOT_EMBEDDED); //2.使用Window系统字体(TrueType) //BaseFont cnFont = BaseFont.createFont("c:\\windows\\Fonts\\STFANGSO.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); //3.使用资源字体(classpath) //BaseFont cnFont = BaseFont.createFont("font/STFANGSO.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); Font contentFont = new Font(cnFont,16, Font.NORMAL, new Color(0,0,0)); String content = "顾行长:"; Paragraph p1 = new Paragraph(content, contentFont); p1.setIndentationLeft(60); p1.setIndentationRight(60); p1.setSpacingBefore(30);//段前插入空白 p1.setLeading(30); String longPara = "为了保证我行科技服务的延续和设备采购的合法合规,信息科技部整理了近期拟签署的服务和采购合同协议21项,累计资金3,315,984.00元(合同所对应的签报、财审会意见清单见附件)。特申请授权信息科技部副总经理石玉军签署下述清单范围内的合同,及相关用印申请。"; Paragraph p2 = new Paragraph(longPara, contentFont); p2.setFirstLineIndent(40);//首行缩进 p2.setAlignment(Paragraph.ALIGN_JUSTIFIED);//对齐方式 p2.setLeading(30);//行间距 p2.setIndentationLeft(60);//左边距,右边距 p2.setIndentationRight(60); Paragraph p3 = new Paragraph("妥否,请批示。", contentFont); p3.setIndentationLeft(60); p3.setIndentationRight(60); p3.setLeading(30); p3.setFirstLineIndent(40); Paragraph p4 = new Paragraph("信息科技部", contentFont); p4.setIndentationLeft(260); p4.setIndentationRight(60); p4.setLeading(30); p4.setFirstLineIndent(40); Paragraph p5 = new Paragraph("2010年7月7日", contentFont); p5.setIndentationLeft(250); p5.setIndentationRight(60); p5.setLeading(30); p5.setFirstLineIndent(40); document.add(p); document.add(p1); document.add(p2); document.add(p3); document.add(p4); document.add(p5); //创建三列的表格 Table table = new Table(4); table.setBorderWidth(1); table.setBorderColor(Color.BLACK); table.setPadding(3); table.setSpacing(0); table.setWidth(80); Font cellFont = new Font(Font.NORMAL,10); table.addCell(new Paragraph("合同(协议)名称", cellFont)); Cell cell = new Cell(new Paragraph("国工商银行股份有限公司北京市分行林大校园卡IBM服务器采购合同", cellFont)); cell.setColspan(3); cell.setHorizontalAlignment(Cell.ALIGN_CENTER); cell.setVerticalAlignment(Cell.ALIGN_MIDDLE); table.addCell(cell); table.addCell(new Paragraph("合同(协议)编号", cellFont)); cell = new Cell(new Paragraph("2010-北京/科技/采购合同-林大、音乐学院校园卡项目-HP", cellFont)); cell.setColspan(3); table.addCell(cell); cell = new Cell(new Paragraph("分行签报", cellFont)); cell.setHorizontalAlignment(Cell.ALIGN_CENTER); cell.setVerticalAlignment(Cell.ALIGN_MIDDLE); table.addCell(cell); table.addCell(new Paragraph("行领导批示:拟同意,请顾行长阅示。付捷 2010-06-18 12:59同意上财审会审议。" + "顾建纲 2010-06-21 13:21/候巍 2010-6-18亚运村支行电子设备审批单", cellFont)); table.addCell(new Paragraph("签报文号", cellFont)); table.addCell(new Paragraph("工银京司二签[2010]114号亚运村支行电子设备审批单", cellFont)); document.add(table); document.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } ...展开收缩
(系统自动生成,下载前可以参看下载内容)

下载文件列表

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
 相关搜索: 导出word
 输入关键字,在本站1000多万海量源码库中尽情搜索: