java itext 导出word 设置字符边框
/ cell2.setBackgroundColor(BaseColor; //.PdfPTable;/ cell1.setBorderWidth(5f), new FileOutputStream("TableCellBorder.doc".GRAY).BaseColor;/ /Cell 2" //Cell 1".close(); document.FileOutputStream;public class TableCellBorderColor { public static void main(String[] args) { Document document = new Document();import com.itextpdf;import com.itextpdf; } }}希望可以帮助到你.BLUE).text.Document; // cell2.addCell(cell2); PdfPCell cell3 = new PdfPCell(new Phrase("Cell 3")).setBorderColorRight(BaseColor.io.FileNotFoundException;import java.io; table.Phrase;import com; cell2.text.DocumentException;import com;s individual border width /.GREEN); cell2.setBorderColorBottom(BaseColor; table.open(); PdfPTable table = new PdfPTable(3); PdfPCell cell1 = new PdfPCell(new Phrase(".setBorderColor(BaseColor.BLUE); table.addCell(cell1);s individual border color /.text.pdf.PdfWriter;import java.itextpdf.text.setBorderWidthLeft(1f); table.addCell(cell3);import com; Setting cell'/ /.printStackTrace();/ cell2.setBorderWidthTop(1f); cell2.setBorderColorTop(BaseColor.RED).pdf; try { PdfWriter.getInstance(document.kodejava.example.itextpdf; cell1.setBorderColorLeft(BaseColor.BLACK);import com.itextpdf.itextpdf.text;)); cell1.setUseBorderPadding(true); // cell3.setBorderWidthTop(2f); cell3.setBorderWidthRight(1f); cell3.setBorderWidthBottom(2f).pdf;)); document.itextpdf.text.itextpdf.text;)); cell2.setUseBorderPadding(true); / //.add(table); } catch (DocumentException | FileNotFoundException e) { e; cell3.setUseBorderPadding(true);/ Setting cell's background color // Setting cell's border width and color / cell3.completeRow().PdfPCell;import com; Setting cell' PdfPCell cell2 = new PdfPCell(new Phrase("亲,这个是我给你写的设置边框和背景色的例子,请参考package org; } finally { document
请教iText生成word问题
使用iText生成word,struts2框架,使用iText-2.1.7.jar和iText-rtf-2.1.7.jar 方法如下: import java.io.*; import java.awt.Color; import com.lowagie.text.*; import com.lowagie.text.rtf.RtfWriter2; import com.lowagie.text.rtf.headerfooter.*; import com.lowagie.text.rtf.field.*; import com.lowagie.text.rtf.table.*; import com.lowagie.text.rtf.style.RtfFont; public class RtfClass { public static String rtf() { com.lowagie.text.Document document = new com.lowagie.text.Document(); try {System.out.println("try1"); RtfWriter2.getInstance(document, new FileOutputStream("C:\rhDocs\testRTFdocument.rtf")); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } document.open(); try {System.out.println("try2"); document.add(new Paragraph("Hello World!")); } catch (DocumentException e) { // TODO Auto-generated catch block e.printSt... 1; } document.*: import java; return ".*.RtfFont.io;/testRTFdocument; document;try1".text; import com.Document document = new com.text.lowagie.headerfooter;rhDocs\.out,struts2框架.Color.field; import com.printStackTrace().close().rtf.text; import com.println(" } document.printStackTrace();).text;try2".text.text.jar 方法如下; import com.*; TODO Auto-generated catch block e.lowagie;)); TODO Auto-generated catch block e.rtf".text.7.*.Document(); import com.lowagie.lowagie.table.RtfWriter2.getInstance(document.style; RtfWriter2; import java.rtf.lowagie;/C, new FileOutputStream(" try {System;ok".println(".awt;)):\!",使用iText-2.open().rtf; import com; public class RtfClass { public static String rtf() { com;Hello World.rtf;.7使用iText生成word.*.rtf.lowagie; } } 我用这个生成绝对不会有问题.1.lowagie; } catch (FileNotFoundException e) { / } catch (DocumentException e) { /.text.lowagie.out.add(new Paragraph("); try {System.jar和iText-rtf-2 展开
java怎样一次导出多个word
要加一些文本到一个矩形框的内部,希望文本到达右边界时自动换行。
超出矩形部分将不显示,可以通过ColumnText类实现。
举个例子:为显示一个指定的短句在坐标(100, 300)和(200,500)间的矩形内居中,使用下面的代码:PdfContentByte cb =writer.DirectContent;ColumnText ct = new ColumnText(cb);ct.setSimpleColumn(phrase,60, 300, 100, 500, 15, Element.ALIGN_CENTER);ct.go();
怎么用java导出word文档
5、Word等文件、插入图片、插入表格等。
填充数据到表格中读取表格数据 ,1.1版增强的功能: 指定文本样式,指定表格样式,不能设置样式。
3:Java2word是一个在java程序中调用 MS Office Word 文档的组件(类库)。
该组件提供了一组简单的接口,以便java程序调用他的服务操作Word 文档。
这些服务包括: 打开文档、新建文档。
Word从2003开始支持XML格式,大致的思路是先用office2003或者2007编辑好word的样式。
经测试这样方式生成的word文档完全符合office标准,样式。
如此,则可动态排版word文档、插入表格,在书签处插入文字,目前只能实现一些简单文件的操作,然后另存为xml,将xml翻译为FreeMarker模板,最后用java来解析FreeMarker模板并输出Doc、查找文字、替换文字。
他的excel处理很强大,对于word还局限于读取、Html文件转化为PDF文件。
功能强大,但是处理样式有点缺陷,简单的导出可以使用。
6:用XML做就很简单了java导出word大致有6种解决方案:1:Jacob是Java-COM Bridge的缩写。
是一种不错的解决方案。
4:iText是著名的开放源码的站点sourceforge一个项目,是用于生成PDF文档的一个java类库。
通过iText不仅可以生成PDF或rtf的文档,而且可以将XML。
使用Jacob自带的DLL动态链接库,并通过JNI的方式实现了在Java平台上对COM程序的调用。
DLL动态链接库的生成需要windows平台的支持。
该方案只能在windows平台实现,是其局限性。
2:Apache POI包括一系列的API,它们可以操作基于MicroSoft OLE 2 Compound Document Format的各种格式文件,可以通过这些API在Java中读写Excel,该方案实现简单,它在Java与微软的COM组件之间构建一座桥梁,插入文字、插入图片:JSP输出样式...
求教用java 生成word!!!
1-apache的POI,此方法对Excel的导出做的很好,目前对Word的导出方面的功能尚未完全。
2-纯JavaScript脚本实现。
主要通过客户端调用本机Office组件来实现。
3-在JSP页面引入头文件实现。
纯JavaScript脚本实现细节方面大体是创建一个word组件ActiveXObject('Word.Application'),用js通过表ID取得表内容然后保存到word,要注意的是js实现有很多不好的地方,例如Internet选项需要把ActiveX空间全部启用,安全级别设置为中。
这样的话岂不是每台机器都要配置一下。
其次每次生成word文档以后弹出对话框(无法保存此文件,因为它已在别处打开(C:\...\STARTUP\Powerword.dot)),出现此问题就需要把C:\Documents and Settings\当前用户名\Application Data\Microsoft\Word\STARTUP下的Powerword.dot文件删除,每次遇到此问题就需要删除文件来解决,十分不方便。
JSP页面引入来实现Word保存就方便多了,但是也有不足的地方,首先如果需要引入如果需要下载的话就引入其实如果大家用框架做就方便多了,比如Struts2。
在Action里直接写如下代码:if(out!=null){String fileName="";fileName+="评价报告.doc";try {HttpServletResponse response = ServletActionContext.getResponse();response.setHeader("Content-disposition","attachment; filename="+new String(fileName.getBytes("GB2312"), "8859_1"));} catch (UnsupportedEncodingException e) {e.printStackTrace();}out是jsp页面表单元素,一个button,用于提交表单到相应Action进行Word下载。
Action设置jsp页面头文件。
这样每次点击button就可以把相应jsp页面的内容保存到Word中并且支持下载,Word中内容并且是可编辑状态。
不足的地方在于由于表内容是动态生成,有的需要先查看在下载Word,就需要另外建立一个新JSP页面进行Word下载,当然首先要在struts.xml里配置好页面转向。
新建立的页面传值同查看页面要保持一样。
java导出word文档后,怎么在客户端提供下载。
。
。
java导出pdf需要用到iText库,iText是著名的开放源码的站点sourceforge一个项目,是用于生成PDF文档的一个java类库。
通过iText不仅可以生成PDF或rtf的文档,而且可以将XML、Html文件转化为PDF文件。
iText的安装非常方便,下载iText.jar文件后,只需要在系统的CLASSPATH中加入iText.jar的路径,在程序中就可以使用iText类库了。
代码如下:public class createPdf { //自己做的一个简单例子,中间有图片之类的 //先建立Document对象:相对应的 这个版本的jar引入的是com.lowagie.text.Document Document document = new Document(PageSize.A4, 36.0F, 36.0F, 36.0F, 36.0F); public void getPDFdemo() throws DocumentException, IOException{ //这个导出用的是 iTextAsian.jar 和iText-2.1.3.jar 属于比较老的方法。
具体下在地址见: //首先 //字体的定义:这里用的是自带的jar里面的字体 BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", false); // 当然你也可以用你电脑里面带的字体库 //BaseFont bfChinese = BaseFont.createFont("C:/WINDOWS/Fonts/SIMSUN.TTC,1",BaseFont.IDENTITY_H, BaseFont.EMBEDDED); //定义字体 注意在最新的包里面 颜色是封装的 Font fontChinese8 = new Font(bfChinese, 10.0F, 0, new Color(59, 54, 54)); //生成pdf的第一个步骤: //保存本地指定路径 saveLocal(); document.open(); ByteArrayOutputStream ba = new ByteArrayOutputStream(); // PdfWriter writer = PdfWriter.getInstance(document, ba); document.open(); //获取此编译的文件路径 String path = this.getClass().getClassLoader().getResource("").getPath(); //获取根路径 String filePath = path.substring(1, path.length()-15); //获取图片路径 找到你需要往pdf上生成的图片 //这里根据自己的获取的路径写 只要找到图片位置就可以 String picPath = filePath +"\\WebContent" +"\\images\\"; //往PDF中添加段落 Paragraph pHeader = new Paragraph(); pHeader.add(new Paragraph(" 你要生成文字写这里", new Font(bfChinese, 8.0F, 1))); //pHeader.add(new Paragraph("文字", 字体 可以自己写 也可以用fontChinese8 之前定义好的 ); document.add(pHeader);//在文档中加入你写的内容 //获取图片 Image img2 = Image.getInstance(picPath +"ccf-stamp-new.png"); //定义图片在文档中显示的绝对位置 img2.scaleAbsolute(137.0F, 140.0F); img2.setAbsolutePosition(330.0F, 37.0F); //将图片添加到文档中 document.add(img2); //关闭文档 document.close(); /*//设置文档保存的文件名 response.setHeader("Content-disposition", "attachment;filename=\""+ new String(("CCF会员资格确认函.pdf").getBytes("GBK"),"ISO-8859-1") + "\""); //设置类型 response.setContentType("application/pdf"); response.setContentLength(ba.size()); ServletOutputStream out = response.getOutputStream(); ba.writeTo(out); out.flush();*/ } public static void main(String[]args) throws DocumentException, IOException{ createPdf pdf= new createPdf(); pdf.getPDFdemo(); } //指定一个文件进行保存 这里吧文件保存到D盘的text.pdf public void saveLocal() throws IOException, DocumentException{ //直接生成PDF 制定生成到D盘test.pdf File file = new File("D:\\text2.pdf"); file.createNewFile(); PdfWriter.getInstance(document, new FileOutputStream(file)); } }
转载请注明出处51数据库 » java导出word文档itext
小小妖姓王