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

      php excel怎么轉(zhuǎn)換成pdf

      php excel轉(zhuǎn)換成pdf的方法:首先在App下建一個文件夾Libs;然后把類庫放進去,并寫好命名空間;接著修改composer.json;最后在項目根目錄下執(zhí)行composer dump-autoload即可。

      php excel怎么轉(zhuǎn)換成pdf

      本文操作環(huán)境:windows7系統(tǒng)、PHP7.1版,DELL G3電腦

      php excel怎么轉(zhuǎn)換成pdf?

      php excel轉(zhuǎn)pdf

      接下來說說excel轉(zhuǎn)pdf這個坑,這個是真坑啊,好多說什么用dompdf、mpdf。最后我都把phpexcel換成PhpSpreadsheet這個了,總算是轉(zhuǎn)換成功了,但是問題來了,中文亂碼,樣式大改變,果斷先放棄,看看別的辦法,實在不行再回來研究。試試之前看的com加openoffice吧,這個可以實現(xiàn),最開始覺得麻煩沒愛用,先上代碼。

      <?php namespace AppLibs;   class Office2pdf { private $osm; public function __construct() { $this->osm = new COM("com.sun.star.ServiceManager")or die ("Please be sure that OpenOffice.org is installed.n");  } public function MakePropertyValue($name,$value) { $oStruct = $this->osm->Bridge_GetStruct("com.sun.star.beans.PropertyValue"); $oStruct->Name = $name; $oStruct->Value = $value; return $oStruct; } public function transform($input_url, $output_url) { $args = array($this->MakePropertyValue("Hidden",true));   $oDesktop = $this->osm->createInstance("com.sun.star.frame.Desktop");   $oWriterDoc = $oDesktop->loadComponentFromURL($input_url,"_blank", 0, $args); $export_args = array($this->MakePropertyValue("FilterName","writer_pdf_Export"));   $oWriterDoc->storeToURL($output_url,$export_args); $oWriterDoc->close(true); return $this->getPdfPages($output_url); } public function run($input,$output) { $input = "file:///" . str_replace("\","/",$input); $output = "file:///" . str_replace("\","/",$output); return $this->transform($input, $output); } /** * 獲取PDF文件頁數(shù)的函數(shù)獲取 * 文件應(yīng)當對當前用戶可讀(linux下) * @param  [string] $path [文件路徑] * @return int */ public function getPdfPages($path) { if(!file_exists($path)) return 0; if(!is_readable($path)) return 0; // 打開文件 $fp=@fopen($path,"r"); if (!$fp)  { return 0; } else  { $max=0; while(!feof($fp))  { $line = fgets($fp,255); if (preg_match('//Count [0-9]+/', $line, $matches)) { preg_match('/[0-9]+/',$matches[0], $matches2); if ($max<$matches2[0]) $max=$matches2[0]; } } fclose($fp); // 返回頁數(shù) return $max; } }   }

      這個方法是轉(zhuǎn)發(fā)的,在這里謝過大神,想必都看到了,有命名空間,那就簡單說一下laravel引用自己的類庫方法吧,度娘都可以找到,在App下建一個文件夾Libs,然后把類庫放進去,寫好命名空間,然后在composer.json中……上代碼

      "autoload": {         "files": [             "app/Libs/Office2pdf.php"         ]     } /*這段是加入的,如果有files直接把你的類文件路徑放進去就行 "files": [             "app/Libs/Office2pdf.php"         ] */

      然后在項目根目錄下執(zhí)行composer dump-autoload,然后在控制器中引用,new就行了

      use appLibsOffice2pdf; $r = new Office2pdf;  //實例化后就可以用了

      邏輯好像出現(xiàn)了一點問題,沒有告訴你們安裝openoffice,去下載一個安裝上,然后需要設(shè)置一下,東西都寫一起了,有點亂啊,接下來上配置,百度都有教程,我也記錄下來吧,方便以后自己用

      OpenOffice 安裝完成之后,按 win+R 快捷鍵進入運行菜單,輸入 Dcomcnfg 打開組件服務(wù)。

      [組件服務(wù)] >> [計算機] >> [我的電腦] >> [DCOM配置] >> [OpenOffice Service Manager]

      右鍵打開屬性面板,選擇安全選項卡,分別在 啟動和激活權(quán)限 和 訪問權(quán)限 上勾選自定義,添加 Everyone 的權(quán)限。權(quán)限全開

      再選擇標識選項卡,勾選 交互式用戶,保存設(shè)置后退出。

      安裝完 OpenOffice 后,需要啟動一次確認軟件可以正常運行,然后再打開命令行運行以下命令:

      切換到安裝目錄: cd C:Program FilesOpenOffice 4program

      后臺運行該軟件: soffice -headless-accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard

      PS:該命令只需要執(zhí)行一次,就可以使軟件一直在后臺運行,即使重啟服務(wù)器也不受影響。

      接下來配置開啟php擴展

      如果是 PHP5.4 以前的版本,需要在 php.ini 里把 com.allow_dcom = true 打開(即去掉前面的分號)。

      如果是 PHP5.4 之后的版本,則要在 php.ini 里增加一行擴展 extension = php_com_dotnet.dll 。

      重啟 Apache 或 IIS 服務(wù)器,打印 phpinfo() 信息,檢查 com_dotnet 擴展是開啟。

      檢查 php 的 ext 目錄中 是否存在 com_dotnet.dll 文件,如果沒有請自行下載對應(yīng)版本的 dll。

      然后用上面的類方法就可以實現(xiàn)excel轉(zhuǎn)pdf了,這里還有一些需要注意的就是打印區(qū)域、打印大小、是否打印到一頁,這個問題要在excel模板中定義好,轉(zhuǎn)換的時候會讀取excel中的源數(shù)據(jù),這個問題也難了我好久,好像就沒有不難的,如果你們厲害可以研究下有沒有接口可以在openoffice中設(shè)置,如果有請把鏈接給我,嘿嘿。

      推薦學習:《PHP視頻教程》

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