久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放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. 站長(zhǎng)資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      用PHP換個(gè)思路讀取WORD內(nèi)容

      用PHP換個(gè)思路讀取WORD內(nèi)容

      項(xiàng)目:?jiǎn)柧?/p>

      需求:WORD 導(dǎo)入問卷

      背景:運(yùn)營(yíng)那里有幾百個(gè) WORD 格式問卷,如果去后臺(tái)手動(dòng)錄入,無疑工作量很大,希望能直接導(dǎo)入。

      心情:接到需求之后五味雜陳,因?yàn)橐郧白鲞^ excel 導(dǎo)入,而且有現(xiàn)成的插件,代碼也是一搜索一堆。

      word 導(dǎo)入無疑涉及到了知識(shí)盲點(diǎn),但是需求就在那里,又懟不過產(chǎn)品同學(xué)!只能硬著頭皮上了。

      難點(diǎn):word 不好讀取內(nèi)容,內(nèi)容讀出來不好結(jié)構(gòu)化。

      解決問題思路:

      先讀取 WORD, 再說怎么結(jié)構(gòu)化。

      讀取 WORD:

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

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

      轉(zhuǎn)換思路:

      既然不能讀取 WORD, 那我可以讀取 HTML, 只需要把 WORD 轉(zhuǎn)換成 HTML 就可以了,然后讀取 HTML 內(nèi)容就行。

      代碼:

      <?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轉(zhuǎn)換HTML         $result=$word->load(storage_path('測(cè)試.docx'));         $write=new PhpOfficePhpWordWriterHTML($result);         $write->save(storage_path().'/測(cè)試.html');         //讀取HTML內(nèi)容         $document=new DOMDocument();         $document->loadHTML(file_get_contents(storage_path('測(cè)試.html')));         $html=simplexml_import_dom($document);         dd((array)$html->body);     } }

      開始測(cè)試:新建 測(cè)試.docx

      測(cè)試.docx 內(nèi)容:

      用PHP換個(gè)思路讀取WORD內(nèi)容

      執(zhí)行腳本:

      php artisan word

      結(jié)果:

      用PHP換個(gè)思路讀取WORD內(nèi)容

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