user itext create a word file
2008-01-05 20:01:44 来源:WEB开发网import java.awt.Color;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;
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
*/
/**
* @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);
- ››user-agent查询方法
- ››userinit.exe出现异常之解决方案
- ››Create ajax
- ››Create Smoke Effect on Grungy Wallpaper
- ››CreateThread与_beginthread的区别
- ››Create a Silhouette Logo for a Steak House Res...
- ››Create a Textured Journal Icon
- ››Create Stylized Vector Dog Tags
- ››user itext create a word file
- ››CreateFolder 方法
- ››CreateTextFile 方法
- ››User Tips: Using Return Values from a SQL Serv...
更多精彩
赞助商链接