当前位置:网站首页>Thinkphp3 use phpword to modify the template and download it
Thinkphp3 use phpword to modify the template and download it
2022-06-25 12:25:00 【sr_ www】
Library Download :PHPWord download , Direct coverage to ThinkPHP root directory
$row=(new PersonModel())->find(\session('person_id'));
// Template and temporary file directory
$tempPath='./doc_templet/';
// Template file
$templetFile=$tempPath.'resume1.docx';
// The temporary file
$saveFile=$tempPath.'resume_'.\session('person_id').'.docx';
// load PHPWord
require_once('./ThinkPHP/Library/Vendor/phpword/PhpWord.php');
require_once('./ThinkPHP/Library/Vendor/phpword/Settings.php');
require_once('./ThinkPHP/Library/Vendor/phpword/TemplateProcessor.php');
require_once('./ThinkPHP/Library/Vendor/phpword/Shared/ZipArchive.php');
require_once('./ThinkPHP/Library/Vendor/phpword/Shared/Text.php');
// Import template
$document=new \PhpOffice\PhpWord\TemplateProcessor($templetFile);
// Replace variable
$document->setValue('name',$row['person_name']);
$document->setValue('sex',$row['person_sex']);
$document->setValue('time',\date('Y-m-d H:i:s'));
// Replace picture
$document->setImageValue('photo_',[
'path'=>$row['person_photo_'],
'width'=>120,
'height'=>180,
]);
// Save temporary files
$document->saveAs($saveFile);
// download ( Output directly to the browser )
ob_clean();
ob_start();
$fp = fopen($saveFile,"r");
$file_size = filesize($saveFile);
Header("Content-type:application/octet-stream");
Header("Accept-Ranges:bytes");
Header("Accept-Length:".$file_size);
Header("Content-Disposition:attchment; filename=".\site('name').'_ resume _'.$row['person_name'].'.docx');
$buffer = 1024;
$file_count = 0;
while (!feof($fp) && $file_count < $file_size){
$file_con = fread($fp,$buffer);
$file_count += $buffer;
echo $file_con;
}
fclose($fp);
ob_end_flush();
// Delete file
//\path_delete($saveFile);
边栏推荐
猜你喜欢

A commonly used statistical modeling method -- difference analysis

Dark horse shopping mall ---3 Commodity management

How to use ARIMA model for prediction?

What are redis avalanche, penetration and breakdown?

Full nanny tutorial of Market Research Competition (experience sharing)

使用php脚本查看已开启的扩展
![[data midrange] what is the oneid of the data midrange? Isn't the master data fragrant?](/img/51/9aceaaeed1f6db7c60685d53477eba.png)
[data midrange] what is the oneid of the data midrange? Isn't the master data fragrant?

K8s, docker compose install MySQL 8.0.18

19. Implementation of MVVM architecture based on WPF event to command
![[oceanbase] Introduction to oceanbase and its comparison with MySQL](/img/1c/bd2bcddb7af4647407d2bc351f5f5d.png)
[oceanbase] Introduction to oceanbase and its comparison with MySQL
随机推荐
R语言使用epiDisplay包的followup.plot函数可视化多个ID(病例)监测指标的纵向随访图、使用stress.type参数指定强调线的id子集的线条的类型(type)
Web project development process
How to use SPSS to do grey correlation analysis? Quick grasp of hand-to-hand Teaching
R语言dplyr包filter函数过滤dataframe数据中指定数据列的内容不是(不等于指定向量中的其中一个)指定列表中的数据行
What is the primordial universe
20. MVVM command binding of WPF
How do super rookies get started with data analysis?
SDN系统方法 | 9. 接入网
20、wpf之MVVM命令绑定
学习笔记 2022 综述 | 自动图机器学习,阐述 AGML 方法、库与方向
揭秘GaussDB(for Redis):全面對比Codis
2020最新最全IT学习线路
Gradle知识点
[oceanbase] Introduction to oceanbase and its comparison with MySQL
SDN system method | 9 Access network
Which securities company's account is better and safer to open
The first techo day Tencent technology open day in 2022 will be held online on June 28
Uncover gaussdb (for redis): comprehensive comparison of CODIS
Mpai data science platform SVM support vector machine classification \ explanation of regression parameter adjustment
网络上开户买股票是否安全呢?