java使用poi将html导出word,默认打开页面视图
2017-05-19 11:04
706 查看
<htmlxmlns:v="urn:schemas-microsoft-com:vml"xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word"xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head>
<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>
<!--[ifgtemso9]><xml><w:WordDocument><w:View>Print</w:View><w:TrackMoves>false</w:TrackMoves><w:TrackFormatting/><w:ValidateAgainstSchemas/><w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid><w:IgnoreMixedContent>false</w:IgnoreMixedContent><w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText><w:DoNotPromoteQF/><w:LidThemeOther>EN-US</w:LidThemeOther><w:LidThemeAsian>ZH-CN</w:LidThemeAsian><w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript><w:Compatibility><w:BreakWrappedTables/><w:SnapToGridInCell/><w:WrapTextWithPunct/><w:UseAsianBreakRules/><w:DontGrowAutofit/><w:SplitPgBreakAndParaMark/><w:DontVertAlignCellWithSp/><w:DontBreakConstrainedForcedTables/><w:DontVertAlignInTxbx/><w:Word11KerningPairs/><w:CachedColBalance/><w:UseFELayout/></w:Compatibility><w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel><m:mathPr><m:mathFontm:val="CambriaMath"/><m:brkBinm:val="before"/><m:brkBinSubm:val="--"/><m:smallFracm:val="off"/><m:dispDef/><m:lMarginm:val="0"/><m:rMarginm:val="0"/><m:defJcm:val="centerGroup"/><m:wrapIndentm:val="1440"/><m:intLimm:val="subSup"/><m:naryLimm:val="undOvr"/></m:mathPr></w:WordDocument></xml><![endif]-->
html页面中添加以上代码默认打开为页面视图而不是web视图
poi将html导出为word
importjava.io.BufferedReader;
importjava.io.ByteArrayInputStream;
importjava.io.File;
importjava.io.FileOutputStream;
importjava.io.FileReader;
importjava.io.IOException;
importorg.apache.poi.poifs.filesystem.DirectoryEntry;
importorg.apache.poi.poifs.filesystem.DocumentEntry;
importorg.apache.poi.poifs.filesystem.POIFSFileSystem;
importorg.springframework.stereotype.Service;
/**
*@ClassName:HtmlToWord
*@Description:TODO(将html文件导出为word)
*@authorxsw
*@date2016-12-28上午11:41:19
*
*/
@Service
publicclassHtmlToWord{
/**
*
*(srcPathhtml文件fileName保存的doc文件)
*@paramTODO
*@returnvoid返回类型
*@authorxsw
*@2016-12-28上午11:47:27
*/
publicvoidhtmlToWord(StringsrcPath,StringfileName)throwsException{
ByteArrayInputStreambais=null;
FileOutputStreamfos=null;
try{
if(!"".equals(fileName)){
FilefileDir=newFile(fileName);
if(fileDir.exists()){
Stringcontent=readFile(srcPath);
byteb[]=content.getBytes();
bais=newByteArrayInputStream(b);
POIFSFileSystempoifs=newPOIFSFileSystem();
DirectoryEntrydirectory=poifs.getRoot();
DocumentEntrydocumentEntry=directory.createDocument("WordDocument",bais);
fos=newFileOutputStream(fileName);
poifs.writeFilesystem(fos);
bais.close();
fos.close();
}
}
}catch(IOExceptione){
e.printStackTrace();
}finally{
if(fos!=null)fos.close();
if(bais!=null)bais.close();
}
}
/**
*读取html文件到字符串
*@paramfilename
*@return
*@throwsException
*/
publicStringreadFile(Stringfilename)throwsException{
StringBufferbuffer=newStringBuffer("");
BufferedReaderbr=null;
try{
br=newBufferedReader(newFileReader(filename));
buffer=newStringBuffer();
while(br.ready())
buffer.append((char)br.read());
}catch(Exceptione){
e.printStackTrace();
}finally{
if(br!=null)br.close();
}
returnbuffer.toString();
}
}
相关文章推荐
- java使用poi将html导出word,默认打开页面视图
- java html导出word默认打开视图设置
- 导出word如何默认打开为页面视图
- 用word生成的jsp,在导出的word打开时,默认以页面视图打开
- 使用Java的POI工具进行Word的DOC文档转为HTML页面技术简介
- Java使用poi将word转换为html
- Java POI Excel导出为HTML页面(去掉行号、列号)
- Java使用poi将word转换为html
- JAVA不使用POI,用PageOffice动态导出Word文档
- 设置word打开文档时默认使用“文档结构图”视图
- Java使用POI导出Word文档
- Java使用poi把html转word保存
- Java-Maven-POI 简单导入导出Excel通用工具,默认使用基于poi实现
- java将html导出成word(利用的poi包导出)
- java将html导出成word(利用的poi包导出)
- 使用BO JAVA SDK打开WEBI报表,并进行PDF、EXCEL、CSV、HTML导出
- jsp导出到word,默认显示为web视图,应该该为页面视图
- Java使用POI导出到Excel。
- 不使用 java.awt.Desktop API,打开默认浏览器访问指定链接的方法
- 使用Java将Word转为Html或txt等···