user itext create a word file

六块砖ok

六块砖ok

2016-02-19 14:30

get新技能是需要付出行动的,即使看得再多也还是要动手试一试。今天图老师小编跟大家分享的是user itext create a word file,一起来学习了解下吧!

  import Java.awt.Color;
  import java.io.FileNotFoundException;
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.net.MalformedURLException;

(本文来源于图老师网站,更多请访问https://m.tulaoshi.com/bianchengyuyan/)

  import com.lowagie.text.*;
  import com.lowagie.text.rtf.*;
  /*
   * Created on 2004-11-10
   *
   * TODO To change the template for this generated file go to
   * Window - Preferences - Java - Code Style - Code Templates
   */

(本文来源于图老师网站,更多请访问https://m.tulaoshi.com/bianchengyuyan/)

  /**
   * @author Administrator
   *
   * TODO To change the template for this generated type comment go to
   * Window - Preferences - Java - Code Style - Code Templates
   */
  public class RTFCreate {

   public static void main(String[] args) throws MalformedURLException, IOException {
    RTFCreate rtfCreate = new RTFCreate();
    try {
     rtfCreate.createRTF();
    } catch (FileNotFoundException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
    } catch (DocumentException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
    }
   }
   public void createRTF() throws DocumentException, BadElementException, MalformedURLException, IOException
   {
    Document document = new Document(PageSize.A4);
    //document.addTitle("Title");
    //document.addHeader("header","Header");
    
    RtfWriter.getInstance(document, new FileOutputStream("C:/World.rtf"));
    
    document.open();
    //add a Word
    document.add(new Paragraph("Hello World!您好!hehe!"));
    //add a table
    Table table = new Table(3);
    table.setBorderWidth(1);
    table.setBorderColor(new Color(0, 0, 255));
    table.setPadding(5);
    table.setSpacing(5);
    Cell cell = new Cell("header");
    cell.setHeader(true);
    cell.setColspan(3);
    table.addCell(cell);
    table.endHeaders();
    cell = new Cell("example cell with colspan 1 and rowspan 2");
    cell.setRowspan(2);
    cell.setBorderColor(new Color(255, 0, 0));
    table.addCell(cell);
    table.addCell("1.1");
    table.addCell("2.1");
    table.addCell("1.2");
    table.addCell("2.2");
    table.addCell("cell test1");
    cell = new Cell("big cell");
    cell.setRowspan(2);
    cell.setColspan(2);
    table.addCell(cell);
    table.addCell("cell test2");
    
    document.add(table);
  

展开更多 50%)
分享

猜你喜欢

user itext create a word file

编程语言 网络编程
user itext create a word file

use itext create a PDF file

编程语言 网络编程
use itext create a PDF file

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

User Scripts: Video Download by User Scripts

Web开发
User Scripts: Video Download by User Scripts

Save a File Using a File Save Dialog Box

Web开发
Save a File Using a File Save Dialog Box

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

Locate a File Using a File Open Dialog Box

Web开发
Locate a File Using a File Open Dialog Box

MySQL进阶_create table篇

MySQL mysql数据库
MySQL进阶_create table篇

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

如何立即预订并免费升级Win10?

如何立即预订并免费升级Win10?

用VB生成DLL封装ASP代码连接数据库

用VB生成DLL封装ASP代码连接数据库
下拉加载更多内容 ↓