使用iText导出Word(含有Table)示例
来源:互联网 发布:alpine linux 编辑:程序博客网 时间:2024/05/29 08:31
使用iText导出Word,需要的Jar包有iText-2.1.7.jar,iTextAsian.jar,iText-rtf-2.1.7.jar
Expert expert=new Expert();
.......expert的一些属性省略
String fileName=new String(("专家信息-"+expert.getName()).getBytes("GBK"),"ISO-8859-1");//文件名称
response.setContentType("application/doc;charset=utf-8");
response.setHeader("Content-disposition", "attachment;filename=" + fileName+".doc");//文件标题,打开类型
com.lowagie.text.Rectangle rect=new com.lowagie.text.Rectangle(com.lowagie.text.PageSize.A4);//设置页面
rect.setBackgroundColor(Color.WHITE);//设置背景色
com.lowagie.text.Document document=new com.lowagie.text.Document(rect);//创建文件
document.setMargins(10, 20, 30, 40);//页边距
RtfWriter2 writer2=RtfWriter2.getInstance(document, response.getOutputStream());//创建书写器与document关联
// 文档属性
document.addTitle("Title@sample"); // 标题
document.addAuthor("Author@nicaisheng");// 作者
document.addSubject("Subject@iText sample");// 主题
document.addKeywords("Keywords@iText");// 关键字
document.addCreator("Creator@iText");// 创建者
//设置字体
com.lowagie.text.pdf.BaseFont bfChinese=com.lowagie.text.pdf.BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
com.lowagie.text.Font fontChinese=new com.lowagie.text.Font(bfChinese, 8, Font.NORMAL);// 创建字体,设置family,size,style,还可以设置color
com.lowagie.text.Font titleChinese=new com.lowagie.text.Font(bfChinese, 20, Font.BOLD);
com.lowagie.text.Font BoldChinese = new com.lowagie.text.Font(bfChinese, 14, Font.BOLD);
com.lowagie.text.Font subBoldFontChinese = new com.lowagie.text.Font(bfChinese, 8, Font.BOLD);
//添加标题
document.open();
com.lowagie.text.Paragraph title=new com.lowagie.text.Paragraph("专家信息",titleChinese);
title.setAlignment(Element.ALIGN_CENTER);
//title.setLeading(1f);
document.add(title);
//生成表格
float[] widths = {25f, 30f, 30f,25f,25f,25f };// 设置表格的列宽和列数 默认是4列
Table table=new Table(6);
table.setWidths(widths);
//table.setSpacing(20f);
//table.setWidth(100);// 设置表格宽度为100%
Cell cell=null;
cell=new Cell(new com.lowagie.text.Paragraph("姓名", subBoldFontChinese));
cell.setBackgroundColor(Color.LIGHT_GRAY);
cell.setHorizontalAlignment(com.lowagie.text.Element.ALIGN_CENTER);
table.addCell(cell);
cell=new Cell(new com.lowagie.text.Paragraph(expert.getName(), fontChinese));
table.addCell(cell);
cell=new Cell(new com.lowagie.text.Paragraph("性别", subBoldFontChinese));
cell.setBackgroundColor(Color.LIGHT_GRAY);
cell.setHorizontalAlignment(com.lowagie.text.Element.ALIGN_CENTER);
table.addCell(cell);
cell=new Cell(new com.lowagie.text.Paragraph(expert.getGender(), fontChinese));
table.addCell(cell);
cell=new Cell(new com.lowagie.text.Paragraph("身份证号", subBoldFontChinese));
cell.setBackgroundColor(Color.LIGHT_GRAY);
cell.setHorizontalAlignment(com.lowagie.text.Element.ALIGN_CENTER);
table.addCell(cell);
cell=new Cell(new com.lowagie.text.Paragraph(expert.getCitizenNumber(), fontChinese));
table.addCell(cell);
document.add(table);
document.close();
- 使用iText导出Word(含有Table)示例
- 使用iText导出PDF(含有Table)示例
- JAVA 使用iText导出PDF(含有Table)示例
- 使用itext导出word文档
- 使用iText导出word和pdf(经典)
- 使用IText实现office Word文档导出
- Java导出Word文档使用iText操作
- iText的使用例子说明(利用Itext画模板导出word、pdf,纯java实现)
- IText导出Word
- itext 导出word
- 利用IText导出Word
- iText导出word、pdf
- iText导出word入门
- IText导出Word文档
- itext导出word
- 利用IText导出Word
- iText 生成Word示例
- itext操作word示例
- C#多线程编程简述
- 甲骨文CEO埃里森:收购Sun是迄今最赚钱交易
- .net中的break、continue、return之间的区别
- java 则表达式校验用户名
- 制定开发计划
- 使用iText导出Word(含有Table)示例
- linux下配置ipv6网关及dhcp服务器
- C#防止反编译.怎么办
- C++中public,protected,private访问
- (封)【PreLoader】 —— 极限研究
- 时钟/数据/地址线上串联一个小电阻有什么作用?
- C# 调用VC Dll (传出参数char*)
- onclick onlongclick ontouch
- jquery validate highlight unhighlight,errorPlacement 合理使用