java讀取word文件,并輸出紅色字體,主要采用的是開(kāi)源的讀取框架,例如Jword,示例如下:
10年積累的網(wǎng)站制作、網(wǎng)站設(shè)計(jì)經(jīng)驗(yàn),可以快速應(yīng)對(duì)客戶對(duì)網(wǎng)站的新想法和需求。提供各種問(wèn)題對(duì)應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識(shí)你,你也不認(rèn)識(shí)我。但先網(wǎng)站設(shè)計(jì)后付款的網(wǎng)站建設(shè)流程,更有湯旺免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
package?com.xxx.common;
import?java.io.FileOutputStream;
import?java.io.IOException;
import?java.util.List;
import?com.lowagie.text.Document;
import?com.lowagie.text.DocumentException;
import?com.lowagie.text.Element;
import?com.lowagie.text.Font;
import?com.lowagie.text.PageSize;
import?com.lowagie.text.Paragraph;
import?com.lowagie.text.pdf.BaseFont;
import?com.lowagie.text.rtf.RtfWriter2;
public?class?WordUtil?{
private?static?Document?document;
private?static?BaseFont?baseFont;
//創(chuàng)建word,并設(shè)置紙張文檔
private?static?void?openWordFile(String?fileName)?throws?DocumentException,
IOException?{
document?=?new?Document(PageSize.A4);
RtfWriter2.getInstance(document,?new?FileOutputStream(fileName));
document.open();
baseFont?=?BaseFont.createFont();
}
//設(shè)置標(biāo)題
private?static?boolean?setTitle(String?title)?throws?DocumentException?{
Font?font?=?new?Font(baseFont,?12,?Font.BOLD);
Paragraph?pTitle?=?new?Paragraph(title?+?"\n");
pTitle.setFont(font);
pTitle.setAlignment(Element.ALIGN_CENTER);
return?document.add(pTitle);
}
//設(shè)置文檔內(nèi)容,以及字體顏色
private?static?boolean?setContent(String?content)?throws?DocumentException?{
Font?font?=?new?Font(baseFont,?10,?Font.NORMAL);
Paragraph?pContent?=?new?Paragraph(content);
pContent.setFont(font);
pContent.setAlignment(Element.ALIGN_LEFT);
pContent.setSpacingAfter(5);
pContent.setFirstLineIndent(20);
return?document.add(pContent);
}
//對(duì)外使用的接口
public?static?boolean?CreateWordFile(String?url,?String?title,
ListString?contents)?{
boolean?returnValue?=?false;
try?{
openWordFile(url);
returnValue?=?setTitle(title);
for?(int?i?=?0;?i??contents.size();?i++)?{
returnValue?=?returnValue??setContent(contents.get(i));
}
document.close();
}?catch?(DocumentException?e)?{
//?TODO?Auto-generated?catch?block
e.printStackTrace();
}?catch?(IOException?e)?{
//?TODO?Auto-generated?catch?block
e.printStackTrace();
}
return?returnValue;
}
//對(duì)外使用的接口
public?static?boolean?CreateWordFile(String?url,?String?title,
String?content)?{
boolean?returnValue?=?false;
try?{
openWordFile(url);
returnValue?=?setTitle(title);
returnValue?=?returnValue??setContent(content);
document.close();
}?catch?(DocumentException?e)?{
//?TODO?Auto-generated?catch?block
e.printStackTrace();
}?catch?(IOException?e)?{
//?TODO?Auto-generated?catch?block
e.printStackTrace();
}
return?returnValue;
}
public?static?void?main(String[]?args?)?{
WordUtil?wordUtil?=?new?WordUtil();
ListString?strList?=?new?ArrayListString();
//傳入內(nèi)容為字符串
wordUtil.CreateWordFile("e:\\word.doc",?"標(biāo)題居中",?"我愛(ài)Java");
//傳入內(nèi)容為字符串List
//wordUtil.CreateWordFile("e:\\word.doc",?"標(biāo)題居中",?strList);
}
}
字體大小及顏色
a:Java代碼區(qū)域的字體大小和顏色:
window -- Preferences -- General -- Appearance -- Colors And Fonts -- Java修改 -- Java Edit Text Font
b:控制臺(tái)
window -- Preferences -- General -- Appearance -- Colors And Fonts -- Debug -- Console font
c:其他文件
window -- Preferences -- General -- Appearance -- Colors And Fonts -- Basic -- Text Font
簡(jiǎn)單設(shè)置如下:
jlabel.setFont(new java.awt.Font("Dialog", 1, 15));
“dialog”代表字體,1代表樣式(1是粗體,0是平常的)15是字號(hào)
//設(shè)置字體
jlabel.setForeground(Color.red);
//設(shè)置顏色
網(wǎng)頁(yè)題目:java打印字體顏色代碼,java打印字體顏色代碼大全
當(dāng)前地址:http://www.rwnh.cn/article24/dsijoce.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)頁(yè)設(shè)計(jì)公司、面包屑導(dǎo)航、域名注冊(cè)、企業(yè)建站、外貿(mào)網(wǎng)站建設(shè)、虛擬主機(jī)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
營(yíng)銷型網(wǎng)站建設(shè)知識(shí)