2012-02-22 113 views
4

我已成功地能夠生成.docx文檔https://github.com/djpate/docxgen,但只要我嘗試包含TinyMCE文本,我不再可以打開文檔。 (非有效字符)。將HTML(tinyMCE)轉換爲WORD(.docx)

有沒有辦法將HTML文本轉換爲docxgen之前轉換以避免這種錯誤?

+0

您是否嘗試過類似下面的東西:html_entity_decode($ HTML,ENT_QUOTES, 「UTF-8」);你是否保存到任何點的文件?你能展示非法角色嗎?它是否是BOM的一部分,即: – Gavin 2012-02-22 21:35:28

+0

http://phpword.codeplex.com/documentation – 2014-06-25 17:12:23

回答

3

我決定去圖書館http://www.phpdocx.com/ Pro版本,因爲它簡化了整個過程。我希望它能滿足我的需求。

+3

這個軟件是隱藏的,你必須付出使用幾乎所有有用的功能,所以它不是一個好的解決方案。 – ZanattMan 2013-01-21 15:39:00

+0

總比沒有好。如果您有更好的解決方案,請隨時添加。 – 2013-01-22 10:11:59

+0

phpdocx.com是否滿足您的需求Tristan? 我也在考慮購買這個(embedHTML()是在專業版) – relipse 2013-02-09 20:14:21

0

另一種解決方案是使用http://htmltodocx.codeplex.com/最近剛剛出來。

但是,我試了一下,它搞砸了我的發票(當然我使用的表,我不應該有)

吉姆

6

最後,我這個答案結算創建文檔(簡單輸出HTML,Word將其識別):

header('Content-Type: application/msword'); 
    header("Content-disposition: attachment; filename=" .date("Y-m-d").".doc"); 
    /* 
    header("Content-type: application/vnd.ms-word"); 
    header("Content-disposition: attachment; filename=" .date("Y-m-d").".rtf"); 
    */ 
    $html = preg_replace('%/[^\\s]+\\.(jpg|jpeg|png|gif)%i', 'http://www.akubocrm.com\\0', $html); 

    print "<html xmlns:v=\"urn:schemas-microsoft-com:vml\""; 
    print "xmlns:o=\"urn:schemas-microsoft-com:office:office\""; 
    print "xmlns:w=\"urn:schemas-microsoft-com:office:word\""; 
    print "xmlns=\"http://www.w3.org/TR/REC-html40\">"; 
    print "<xml> 
    <w:WordDocument> 
     <w:View>Print</w:View> 
     <w:DoNotHyphenateCaps/> 
     <w:PunctuationKerning/> 
     <w:DrawingGridHorizontalSpacing>9.35 pt</w:DrawingGridHorizontalSpacing> 
     <w:DrawingGridVerticalSpacing>9.35 pt</w:DrawingGridVerticalSpacing> 
    </w:WordDocument> 
    </xml> 
    "; 

    die($html);