poitohtml
㈠ 用poi 實現word to html ,圖片顯示方框,該如何處理
可以!
㈡ poi實現excel轉html時,如何去掉sheet1,sheet2,設sheet3等字樣
wb.setSheetName(" ");把sheet的name改為空格,界面上就不顯示了:)
㈢ poi的word轉html,怎麼顯示修訂內容的最終狀態
實現代碼如下:
public class Word2Html { public static void main(String argv[]) { try { //word 路徑 html輸出路徑 convert2Html("D:/doctohtml/1.doc","D:/doctohtml/1.html"); } catch (Exception e) { e.printStackTrace(); } } public static void writeFile(String content, String path) { FileOutputStream fos = null; BufferedWriter bw = null; try { File file = new File(path); fos = new FileOutputStream(file); bw = new BufferedWriter(new OutputStreamWriter(fos,"utf-8")); bw.write(content); } catch (FileNotFoundException fnfe) { fnfe.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } finally { try { if (bw != null) bw.close(); if (fos != null) fos.close(); } catch (IOException ie) { } } } public static void convert2Html(String fileName, String outPutFile) throws TransformerException, IOException, ParserConfigurationException { HWPFDocument wordDocument = new HWPFDocument(new FileInputStream(fileName));//WordToHtmlUtils.loadDoc(new FileInputStream(inputFile)); WordToHtmlConverter wordToHtmlConverter = new WordToHtmlConverter( DocumentBuilderFactory.newInstance().newDocumentBuilder() .newDocument()); wordToHtmlConverter.setPicturesManager( new PicturesManager() { public String savePicture( byte[] content, PictureType pictureType, String suggestedName, float widthInches, float heightInches ) { //html 中 圖片標簽中 顯示的圖片路路徑 <img src="d:/test/0.jpg"/> return "d:/doctohtml/"+suggestedName; } } ); wordToHtmlConverter.processDocument(wordDocument); //save pictures List pics=wordDocument.getPicturesTable().getAllPictures(); if(pics!=null){ for(int i=0;i<pics.size();i++){ Picture pic = (Picture)pics.get(i); System.out.println(); try { //word中圖片的存儲路徑 pic.writeImageContent(new FileOutputStream("D:/doctohtml/" + pic.suggestFullFileName())); } catch (FileNotFoundException e) { e.printStackTrace(); } } } Document htmlDocument = wordToHtmlConverter.getDocument(); ByteArrayOutputStream out = new ByteArrayOutputStream(); DOMSource domSource = new DOMSource(htmlDocument); StreamResult streamResult = new StreamResult(out); TransformerFactory tf = TransformerFactory.newInstance(); Transformer serializer = tf.newTransformer(); serializer.setOutputProperty(OutputKeys.ENCODING, "utf-8"); serializer.setOutputProperty(OutputKeys.INDENT, "yes"); serializer.setOutputProperty(OutputKeys.METHOD, "html"); serializer.transform(domSource, streamResult); out.close(); writeFile(new String(out.toByteArray()), outPutFile); }}
㈣ スポイト是什麼意思及用法
【スポイト】【supoito】◎
【名詞】
【英】spuit ;玻璃吸管,(一端帶橡皮囊的)吸液體玻璃管,抽水管。(ガラス管の一端にゴム袋がついているもの。インク・薬液などを吸い上げて他のものに移し入れたり、點滴したりするのに用いる。)
スポイトで入れる。/用玻璃吸管灌進去。
㈤ poi的word轉html,怎麼顯示修訂內容的最終狀態
public class Word2Html {
public static void main(String argv[]) {
try {
//word 路徑 html輸出路徑
convert2Html("D:/doctohtml/1.doc","D:/doctohtml/1.html");
} catch (Exception e) {
e.printStackTrace();
}
}
public static void writeFile(String content, String path) {
FileOutputStream fos = null;
BufferedWriter bw = null;
try {
File file = new File(path);
fos = new FileOutputStream(file);
bw = new BufferedWriter(new OutputStreamWriter(fos,"utf-8"));
bw.write(content);
} catch (FileNotFoundException fnfe) {
fnfe.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
} finally {
try {
if (bw != null)
bw.close();
if (fos != null)
fos.close();
} catch (IOException ie) {
}
}
}
public static void convert2Html(String fileName, String outPutFile)
throws TransformerException, IOException,
ParserConfigurationException {
HWPFDocument wordDocument = new HWPFDocument(new FileInputStream(fileName));//WordToHtmlUtils.loadDoc(new FileInputStream(inputFile));
WordToHtmlConverter wordToHtmlConverter = new WordToHtmlConverter(
DocumentBuilderFactory.newInstance().newDocumentBuilder()
.newDocument());
wordToHtmlConverter.setPicturesManager( new PicturesManager()
{
public String savePicture( byte[] content,
PictureType pictureType, String suggestedName,
float widthInches, float heightInches )
{
//html 中 圖片標簽中 顯示的圖片路路徑 <img src="d:/test/0.jpg"/>
return "d:/doctohtml/"+suggestedName;
}
} );
wordToHtmlConverter.processDocument(wordDocument);
//save pictures
List pics=wordDocument.getPicturesTable().getAllPictures();
if(pics!=null){
for(int i=0;i<pics.size();i++){
Picture pic = (Picture)pics.get(i);
System.out.println();
try {
//word中圖片的存儲路徑
pic.writeImageContent(new FileOutputStream("D:/doctohtml/"
+ pic.suggestFullFileName()));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
Document htmlDocument = wordToHtmlConverter.getDocument();
ByteArrayOutputStream out = new ByteArrayOutputStream();
DOMSource domSource = new DOMSource(htmlDocument);
StreamResult streamResult = new StreamResult(out);
TransformerFactory tf = TransformerFactory.newInstance();
Transformer serializer = tf.newTransformer();
serializer.setOutputProperty(OutputKeys.ENCODING, "utf-8");
serializer.setOutputProperty(OutputKeys.INDENT, "yes");
serializer.setOutputProperty(OutputKeys.METHOD, "html");
serializer.transform(domSource, streamResult);
out.close();
writeFile(new String(out.toByteArray()), outPutFile);
}
}
㈥ poi的word轉html,怎麼顯示修訂內容的最終狀態
實現代碼如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
public class Word2Html {
public static void main(String argv[]) {
try {
//word 路徑 html輸出路徑
convert2Html("D:/doctohtml/1.doc","D:/doctohtml/1.html");
} catch (Exception e) {
e.printStackTrace();
}
}
public static void writeFile(String content, String path) {
FileOutputStream fos = null;
BufferedWriter bw = null;
try {
File file = new File(path);
fos = new FileOutputStream(file);
bw = new BufferedWriter(new OutputStreamWriter(fos,"utf-8"));
bw.write(content);
} catch (FileNotFoundException fnfe) {
fnfe.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
} finally {
try {
if (bw != null)
bw.close();
if (fos != null)
fos.close();
} catch (IOException ie) {
}
}
}
public static void convert2Html(String fileName, String outPutFile)
throws TransformerException, IOException,
ParserConfigurationException {
HWPFDocument wordDocument = new HWPFDocument(new FileInputStream(fileName));//WordToHtmlUtils.loadDoc(new FileInputStream(inputFile));
WordToHtmlConverter wordToHtmlConverter = new WordToHtmlConverter(
DocumentBuilderFactory.newInstance().newDocumentBuilder()
.newDocument());
wordToHtmlConverter.setPicturesManager( new PicturesManager()
{
public String savePicture( byte[] content,
PictureType pictureType, String suggestedName,
float widthInches, float heightInches )
{
//html 中 圖片標簽中 顯示的圖片路路徑 <img src="d:/test/0.jpg"/>
return "d:/doctohtml/"+suggestedName;
}
} );
wordToHtmlConverter.processDocument(wordDocument);
//save pictures
List pics=wordDocument.getPicturesTable().getAllPictures();
if(pics!=null){
for(int i=0;i<pics.size();i++){
Picture pic = (Picture)pics.get(i);
System.out.println();
try {
//word中圖片的存儲路徑
pic.writeImageContent(new FileOutputStream("D:/doctohtml/"
+ pic.suggestFullFileName()));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
Document htmlDocument = wordToHtmlConverter.getDocument();
ByteArrayOutputStream out = new ByteArrayOutputStream();
DOMSource domSource = new DOMSource(htmlDocument);
StreamResult streamResult = new StreamResult(out);
TransformerFactory tf = TransformerFactory.newInstance();
Transformer serializer = tf.newTransformer();
serializer.setOutputProperty(OutputKeys.ENCODING, "utf-8");
serializer.setOutputProperty(OutputKeys.INDENT, "yes");
serializer.setOutputProperty(OutputKeys.METHOD, "html");
serializer.transform(domSource, streamResult);
out.close();
writeFile(new String(out.toByteArray()), outPutFile);
}
}
㈦ poIIutants是什麼意思
poIIutants中文的意思是:一品紅。
㈧ 利用poi如何將條形碼寫入word中
/**條形碼工具類
*/
publicclassOneBarcodeUtil{
publicvoidtool(Stringstr)
{
try
{
JBarcodelocalJBarcode=newJBarcode(EAN13Encoder.getInstance(),WidthCodedPainter.getInstance(),EAN13TextPainter.getInstance());
//生成.歐洲商品條碼(=EuropeanArticleNumber)
//這里我們用作圖書條碼
//Stringstr="788515004012";
=localJBarcode.createBarcode(str);
saveToGIF(localBufferedImage,"EAN13.gif");
localJBarcode.setEncoder(Code39Encoder.getInstance());
localJBarcode.setPainter(WideRatioCodedPainter.getInstance());
localJBarcode.setTextPainter(BaseLineTextPainter.getInstance());
localJBarcode.setShowCheckDigit(false);
//xx
//str="JBARCODE-39";
//localBufferedImage=localJBarcode.createBarcode(str);
//saveToPNG(localBufferedImage,"Code39.png");
}
catch(ExceptionlocalException)
{
localException.printStackTrace();
}
}
staticvoidsaveToJPEG(,StringparamString)
{
saveToFile(paramBufferedImage,paramString,"jpeg");
}
staticvoidsaveToPNG(,StringparamString)
{
saveToFile(paramBufferedImage,paramString,"png");
}
staticvoidsaveToGIF(,StringparamString)
{
saveToFile(paramBufferedImage,paramString,"gif");
}
staticvoidsaveToFile(,StringparamString1,StringparamString2)
{
try
{
=newFileOutputStream("d:/images/"+paramString1);
ImageUtil.encodeAndWrite(paramBufferedImage,paramString2,localFileOutputStream,96,96);
localFileOutputStream.close();
}
catch(ExceptionlocalException)
{
localException.printStackTrace();
}
}
}
/**
*word設置文檔格式
*/
XWPFDocumentxdoc=newXWPFDocument();
XWPFParagraphp=xdoc.createParagraph();
//固定值25磅
setParagraphSpacingInfo(p,true,"0","150",null,null,true,"500",
STLineSpacingRule.EXACT);
//左對齊
setParagraphAlignInfo(p,ParagraphAlignment.LEFT,
TextAlignment.CENTER);
XWPFRunpRun=getOrAddParagraphFirstRun(p,false,false);
// setParagraphRunFontInfo(p,pRun,"**********調度單","黑體",
// "TimesNewRoman","24",false,false,false,false,null,null,
// 0,0,90);
setParagraphRunFontInfo(p,pRun,"oneBarcodeUtil.tool(waybill.getWaybillNo())","黑體",
"TimesNewRoman","24",false,false,false,false,null,null,
0,0,90);
p=xdoc.createParagraph();
//單倍行距
setParagraphSpacingInfo(p,true,"0","0","0","0",true,"240",
STLineSpacingRule.AUTO);
setParagraphAlignInfo(p,ParagraphAlignment.LEFT,TextAlignment.CENTER);
pRun=getOrAddParagraphFirstRun(p,false,false);
setParagraphRunFontInfo(p,pRun,"調度類型:"+departure.getDepartureType()+"制單人:"+departure.getCreator()+"列印時間:"+departure.getCreateTime(),"宋體",
"TimesNewRoman","15",false,false,false,false,null,null,
10,6,0);
如何將條形碼輸入:以下是要實現的效果
㈨ poi的word轉html,如何顯示修訂內容的最終狀態
實現代碼如下:
java">publicclassWord2Html{
publicstaticvoidmain(Stringargv[]){
try{
//word路徑html輸出路徑
convert2Html("D:/doctohtml/1.doc","D:/doctohtml/1.html");
}catch(Exceptione){
e.printStackTrace();
}
}
publicstaticvoidwriteFile(Stringcontent,Stringpath){
FileOutputStreamfos=null;
BufferedWriterbw=null;
try{
Filefile=newFile(path);
fos=newFileOutputStream(file);
bw=newBufferedWriter(newOutputStreamWriter(fos,"utf-8"));
bw.write(content);
}catch(FileNotFoundExceptionfnfe){
fnfe.printStackTrace();
}catch(IOExceptionioe){
ioe.printStackTrace();
}finally{
try{
if(bw!=null)
bw.close();
if(fos!=null)
fos.close();
}catch(IOExceptionie){
}
}
}
publicstaticvoidconvert2Html(StringfileName,StringoutPutFile)
throwsTransformerException,IOException,
ParserConfigurationException{
HWPFDocumentwordDocument=newHWPFDocument(newFileInputStream(fileName));//WordToHtmlUtils.loadDoc(newFileInputStream(inputFile));
=newWordToHtmlConverter(
DocumentBuilderFactory.newInstance().newDocumentBuilder()
.newDocument());
wordToHtmlConverter.setPicturesManager(newPicturesManager()
{
publicStringsavePicture(byte[]content,
PictureTypepictureType,StringsuggestedName,
floatwidthInches,floatheightInches)
{
//html中圖片標簽中顯示的圖片路路徑<imgsrc="d:/test/0.jpg"/>
return"d:/doctohtml/"+suggestedName;
}
});
wordToHtmlConverter.processDocument(wordDocument);
//savepictures
Listpics=wordDocument.getPicturesTable().getAllPictures();
if(pics!=null){
for(inti=0;i<pics.size();i++){
Picturepic=(Picture)pics.get(i);
System.out.println();
try{
//word中圖片的存儲路徑
pic.writeImageContent(newFileOutputStream("D:/doctohtml/"
+pic.suggestFullFileName()));
}catch(FileNotFoundExceptione){
e.printStackTrace();
}
}
}
DocumenthtmlDocument=wordToHtmlConverter.getDocument();
ByteArrayOutputStreamout=newByteArrayOutputStream();
DOMSourcedomSource=newDOMSource(htmlDocument);
StreamResultstreamResult=newStreamResult(out);
TransformerFactorytf=TransformerFactory.newInstance();
Transformerserializer=tf.newTransformer();
serializer.setOutputProperty(OutputKeys.ENCODING,"utf-8");
serializer.setOutputProperty(OutputKeys.INDENT,"yes");
serializer.setOutputProperty(OutputKeys.METHOD,"html");
serializer.transform(domSource,streamResult);
out.close();
writeFile(newString(out.toByteArray()),outPutFile);
}
}
㈩ javaPOI把excel轉換成html 中怎麼去掉序號列
excelToHtmlConverter.setOutputColumnHeaders(false);
excelToHtmlConverter.setOutputRowNumbers(false);
就可以了。