>首先 安裝 phpword: composer require phpoffice/phpword
`
~~~
/**
* @author: Jackhhy
* @date: 2019/12/28 0028
* @name: export
* @describe:內容文本導出word下載和保存到本地
*/
public function export(){
$str='需要導出到word的字符串';
$phpWord=new PhpWord(); //實例化
//調整頁面樣式
$sectionStyle = array('orientation' => null,
'marginLeft' => 400,
'marginRight' => 400,
'marginTop' => 400,
'marginBottom' => 400);
$section = $phpWord->addSection($sectionStyle);
//添加頁眉
$header=$section->addHeader();
$k=$header->addTextRun();
//頁眉添加一張圖片
$k->addImage(ROOT_PATH.'public'.DS_PROS."jrkadmin/admin/images/a.jpg",array(
'width' => '100%',
'height' => 60,
'marginTop' => -1,
'marginLeft' => 1,
'wrappingStyle' => 'behind',
));
//添加頁腳
$footer = $section->addFooter();
$f=$footer->addTextRun();
$f->addImage(ROOT_PATH.'public'.DS_PROS."jrkadmin/admin/images/a.jpg",array(
'width' => 580,
'height' => 140,
'marginTop' => -1,
'marginLeft' => 1,
'wrappingStyle' => 'behind',
));
$footer->addPreserveText('Page {PAGE} of {NUMPAGES}.',array('align'=>'center'));
$section->addText(
'標題',
array('name' => '黑體', 'size' => 15),
array('align'=>'center')
);
//添加換行符
$section->addTextBreak(2);
//添加文本
$section->addText(
$str,
array('name' => 'Arial', 'size' => 13),
array('lineHeight'=>1.5,'indent'=>1)
);
/*直接下載文檔*/
//$tk=parent::makeToken();
$name=time().".docx"; //文件名稱
$phpWord->save($name,"Word2007",true);
/*保存文檔到本地*/
/* $objwrite =IOFactory::createWriter($phpWord);
$t = date("Ymd", time());
$pk = md5($t);//
//保存的路徑和中文名稱適應
$dir = iconv("UTF-8", "GBK", ROOT_PATH.'public'.DS_PROS.'uploads'.DS."save/".$t);
if (!file_exists($dir)) {
@mkdir($dir, 0777, true);
}
$pa = "save/".$t."/".$pk.".docx";
$objwrite->save(ROOT_PATH.'public'.DS_PROS.'uploads'.DS_PROS.$pa);
$this->success("", '', 'http://www.scirobot.com.cn/public/uploads/'.$pa);*/
exit();
}
~~~
`
- 空白目錄
- thinkphp5
- tools-常用類庫
- redis類庫
- Excel類庫
- File文件操作類庫
- Http請求類庫
- Maile郵件發送
- Hooks行為鉤子
- 七牛云
- 隨機數和字符串生成
- 字符串處理
- 時間類處理
- tree型轉換
- 工具類庫
- 文件打包下載
- 常用功能
- 文件上傳
- php生成word文檔
- elasticsearch 基本搜索
- 使用jwt開發API接口
- 安裝模及搭建
- ApiCheck.php
- ApiCheckLogin.php
- common.php
- Login.php
- Comment.php
- 漢字轉拼音
- 安裝使用
- Pinyin類
- elasticsearch操作
- 常用方法
- 數據源生成layui-select
- 獲取自定義配置項
- 百度編輯器
- 格式化文件大小
- 多語言設置
- hook監聽
- 域名綁定到模塊
- thinkphp6
- 文件上傳
- tp5totp6
- 創建路徑
- 獲取類所有方法
- password_hash加密驗證
- 生成 qrcode
- 郵件發送
- 獲取QQ信息
- GoogleAuthenticator
- redis限流
- redis 加鎖
- 百度翻譯
- QueryList爬取數據
- 獲取時間類
- 命令
- Git常用命令
- easyswoole
- pix_qrcode
- 驗證 cpf,cnpj
- php常用方法
- 日志
- 卡通頭像
- 兩位小數
- 圖片轉base64
- auth加密解密
- phpoffice/phpspreadsheet導入導出
- fastadmin
- 樹結構
- 單選框
- 復選框
- 二級搜索
- select選擇框
- selectpage選中回調事件
- 標簽添加
- 修改where條件
- 表格列表中添加input框
- selectpage事件
- fieldlist
- js操作
- test_js
- 多表格
- template模板