日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

itext库产生word文档示例(.doc)

發(fā)布時間:2025/5/22 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 itext库产生word文档示例(.doc) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

itext庫生產(chǎn)word文檔示例

1 // 設(shè)置中文字體------------------------------------------------
2 BaseFont bfChinese = BaseFont.createFont("STSongStd-Light",
3 "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
4 // 標(biāo)題字體風(fēng)格
5 Font titleFont = new Font(bfChinese, 12, Font.BOLD);
6 // 正文字體風(fēng)格
7 Font contextFont = new Font(bfChinese, 10, Font.NORMAL);
8
9 // 新建標(biāo)題,設(shè)置格式對齊方式------------------------
10 Paragraph title = new Paragraph("標(biāo)題");
11 title.setAlignment(Element.ALIGN_CENTER);
12 title.setFont(titleFont);
13 document.add(title);
14
15 // 創(chuàng)建新段落,設(shè)置格式---------------------------
16 Paragraph context = new Paragraph("測試:測試:測試:測試:測試:測試:");
17 context.setAlignment(Element.ALIGN_LEFT);
18 context.setFont(contextFont);
19 context.setSpacingBefore(3);// 段間距
20 context.setFirstLineIndent(20);// 設(shè)置第一行空的列數(shù)
21 document.add(context);
22
23 // 創(chuàng)建一個三列的表格------------------------------
24 Table table = new Table(3);
25 int width[] = { 25, 25, 50 };// 設(shè)置每列寬度比例
26 table.setWidths(width);
27 table.setWidth(90);// 占頁面寬度比例
28 table.setAlignment(Element.ALIGN_CENTER);// 居中
29 table.setAlignment(Element.ALIGN_MIDDLE);// 垂直居中
30 table.setAutoFillEmptyCells(true);// 自動填滿
31 table.setBorderWidth(1);// 邊框?qū)挾?/span>
32
33 Cell haderCell = new Cell("表格表頭");// 設(shè)置表頭
34 haderCell.setHeader(true);
35 haderCell.setColspan(3);
36 table.addCell(haderCell);
37 table.endHeaders();
38 Font fontChinese = new Font(bfChinese, 12, Font.NORMAL, Color.GREEN);
39 Cell cell = new Cell(new Paragraph("這是一個3*3測試表格數(shù)據(jù)", fontChinese));
40 cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
41 table.addCell(cell);
42 table.addCell(new Cell("#1"));
43 table.addCell(new Cell("#2"));
44 table.addCell(new Cell("#3"));
45
46 document.add(table);
47 document.close();
48
49 }


(一)生產(chǎn)文件直接存儲到本地

1 RtfWriter2.getInstance(document, new FileOutputStream("D://fileName.doc"));

(二)生產(chǎn)文件 存到數(shù)據(jù)庫中

ByteArrayOutputStream outputStream=new ByteArrayOutputStream();
RtfWriter2.getInstance(document, outputStream);

文件信息形式轉(zhuǎn)化:ByteArrayOutputStream->InputStream->Blob

如:ByteArrayOutputStream outStream=new ByteArrayOutputStream();
InputStream inStream = new ByteArrayInputStream(outStream.toByteArray());
Blob fileObject = Hibernate.createBlob(inStream);
詳見博文"?文檔上傳(通過網(wǎng)頁上傳到服務(wù)器)..."

(三)生產(chǎn)文件 供下載

OutputStream outputStream;
RtfWriter2.getInstance(document, outputStream);
詳見博文"?文件下載(從數(shù)據(jù)庫下載到本地)…"

轉(zhuǎn)載于:https://www.cnblogs.com/windlaughing/archive/2012/03/24/2415623.html

總結(jié)

以上是生活随笔為你收集整理的itext库产生word文档示例(.doc)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。