0
我使用下面的代碼轉換成Word到HTML文件的Apache POI字到HTML的轉換 - 換句話說boundry
public Map convert(String wordDocPath, String htmlPath,
Map conversionParams)
{
log.info("Converting word file "+wordDocPath)
try
{
String workingFolder = "C:\temp"
File workingFolderFile = new File(workingFolder)
FileInputStream fis = new FileInputStream(wordDocPath);
XWPFDocument document = new XWPFDocument(fis);
XHTMLOptions options = XHTMLOptions.create().URIResolver(new FileURIResolver(workingFolderFile));
options.setExtractor(new FileImageExtractor(workingFolderFile))
File htmlFile = new File(htmlPath);
OutputStream out = new FileOutputStream(htmlFile)
XHTMLConverter.getInstance().convert(document, out, options);
log.info("Converted to HTML file "+htmlPath)
}
catch(Exception e)
{
log.error("Exception :"+e.getMessage(),e)
}
}
代碼正確生成HTML輸出。
我需要在文檔中加入一些參數,如[[AGENT_NAME]]
,我將在後面的代碼中用正則表達式替換。但是,apache poi並沒有將這種模式視爲單個字詞,而是將某些標籤插入其間的樣式中[[「,」]。我無法編寫正則表達式,並因此而替換參數。
apache poi如何決定字邊界?有沒有辦法控制它?
的Apache POI未在字邊界決定,這將是微軟Word的選項生成時原始文件... – Gagravarr
可以解釋一下嗎?任何鏈接都會有幫助。有沒有特殊字符是字邊界的一部分? – Fayaz
調試代碼(XWPFDocument.paragraphs)並通過OpenOffice規範http://officeopenxml.com/WPparagraph.php,我瞭解到MsWord可以將文本分割成文檔中的任何位置。它甚至可以拆分不含任何特殊字符(如AGENTNAME)的簡單連續文本。但我們可以控制這種行爲嗎?如何將文本視爲一次運行? – Fayaz