久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網
      最全最豐富的資訊網站

      用PHP換個思路讀取WORD內容

      用PHP換個思路讀取WORD內容

      項目:問卷

      需求:WORD 導入問卷

      背景:運營那里有幾百個 WORD 格式問卷,如果去后臺手動錄入,無疑工作量很大,希望能直接導入。

      心情:接到需求之后五味雜陳,因為以前做過 excel 導入,而且有現(xiàn)成的插件,代碼也是一搜索一堆。

      word 導入無疑涉及到了知識盲點,但是需求就在那里,又懟不過產品同學!只能硬著頭皮上了。

      難點:word 不好讀取內容,內容讀出來不好結構化。

      解決問題思路:

      先讀取 WORD, 再說怎么結構化。

      讀取 WORD:

      一開始想著用 PHPWORD, 畢竟 PHPOFFICE 這么成熟的插件應該可以直接讀取到 WORD 內容吧。

      然而現(xiàn)實很骨感,找遍了文檔并沒有找到直接讀取到 WORD 內容的方法。PHPWORD 只提供了把 WORD 轉換成 HTML,TDF 的方法。

      轉換思路:

      既然不能讀取 WORD, 那我可以讀取 HTML, 只需要把 WORD 轉換成 HTML 就可以了,然后讀取 HTML 內容就行。

      代碼:

      <?php namespace AppConsoleCommands; use IlluminateConsoleCommand; use PhpOfficePhpSpreadsheetReaderHtml; use PhpOfficePhpWordReaderWord2007; class Test extends Command {     /**      * The name and signature of the console command.      *      * @var string      */     protected $signature = 'word';     /**      * The console command description.      *      * @var string      */     protected $description = 'word';     /**      * Create a new command instance.      *      * @return void      */     public function __construct() {         parent::__construct();     }     /**      * Execute the console command.      *      * @return int      */     public function handle(Word2007 $word) {         //WORD轉換HTML         $result=$word->load(storage_path('測試.docx'));         $write=new PhpOfficePhpWordWriterHTML($result);         $write->save(storage_path().'/測試.html');         //讀取HTML內容         $document=new DOMDocument();         $document->loadHTML(file_get_contents(storage_path('測試.html')));         $html=simplexml_import_dom($document);         dd((array)$html->body);     } }

      開始測試:新建 測試.docx

      測試.docx 內容:

      用PHP換個思路讀取WORD內容

      執(zhí)行腳本:

      php artisan word

      結果:

      用PHP換個思路讀取WORD內容

      贊(0)
      分享到: 更多 (0)
      網站地圖   滬ICP備18035694號-2    滬公網安備31011702889846號