当前位置:网站首页>phpexcel导出数据为xml
phpexcel导出数据为xml
2022-08-04 05:25:00 【eleven_-11】
phpexcel导出数据为xml
参考借鉴
https://zixuephp.net/article-34.html
https://blog.csdn.net/qq_42751377/article/details/81155313
/** * 导出日志 * * @param $idList * * @return string */
public function exportLog ($idList="")
{
$logModel = new JobLog();
$arrData = $logModel->exportData($idList);
$sXmlName = "任务日志";
//初始化数据表信息
$arrXmlCell = array(
array("id", '日志编号'),
array("log_code", '日志码'),
array("host_uuid", '主机编号'),
array("host_name", '生产系统'),
array("host_ip", 'IP地址'),
array("job_id", '任务ID'),
array("job_name", '任务名称'),
array("task_id", 'task_id'),
array("created_at", '创建时间'),
array("log_module_id", '日志模块id'),
array("job_module_id", '任务模块id'),
array("user_type", '用户类型'),
array("user_name", '用户名'),
array("log_level", '日志级别'),
array("detail", '概要'),
array("user_id", '用户ID'),
array("deleted_at", '删除时间'),
array("meta", '额外信息'),
array("description", '内容')
);
$arrCellName = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','AA','AB','AC','AD','AE','AF','AG','AH','AI','AJ','AK','AL','AM','AN','AO','AP','AQ','AR','AS','AT','AU','AV','AW','AX','AY','AZ');
$phpExcel = new \PHPExcel();
//创建人
$phpExcel->getProperties()->setCreator("user");
//最后修改人
$phpExcel->getProperties()->setLastModifiedBy("user");
//标题
$phpExcel->getProperties()->setTitle("Office 2007 XLSX all user list Document");
//题目
$phpExcel->getProperties()->setSubject("Office 2007 XLSX all user list Document");
//描述
$phpExcel->getProperties()->setDescription("all user list");
//关键字
$phpExcel->getProperties()->setKeywords("all user list");
//种类
$phpExcel->getProperties()->setCategory("office document");
//设置当前的sheet
$phpExcel->setActiveSheetIndex(0);
//设置表头
for ($i = 0; $i < count($arrXmlCell) - 1; $i++){
$phpExcel->getActiveSheet()->setCellValue("{$arrCellName[$i]}1", "{$arrXmlCell[$i][1]}");
}
foreach($arrData as $key=>$val){
$key+=2;
for ($j = 0; $j < count($val)-1; $j++){
$phpExcel->getActiveSheet()->setCellValue("{$arrCellName[$j]}{$key}", "{$val[$arrXmlCell[$j][0]]}");
}
}
// 高置列的宽度
// for ($i = 0; $i < count($arrXmlCell) - 1; $i++){
// $phpExcel->getActiveSheet()->getColumnDimension("{$arrCellName[$i]}")->setWidth(30);
// }
// ob_end_clean(); //清除缓存防止乱码
header('pragma:public');
header('Content-type:application/vnd.ms-excel;charset=utf-8;name="'.$sXmlName.'.xls"');
header("Content-Disposition:attachment;filename=$sXmlName.xls");//attachment新窗口打印inline本窗口打印
$objWriter = \PHPExcel_IOFactory::createWriter($phpExcel, 'Excel5');
$objWriter->save('php://output');
exit;
}
/** * 导出日志信息 */
public function exportData($idList)
{
$model = $this->M();
if (!empty($idList)){
$arrList = explode(',', $idList);
$model->whereIn('id', $arrList);
}
return $model->get();
}
边栏推荐
- 部署LVS-DR群集【实验】
- 想好了吗?
- Embedded system driver primary [4] - under the basis of character device driver _ concurrency control
- 动态规划总括
- EntityComponentSystemSamples学习笔记
- C Expert Programming Chapter 5 Thinking about Chaining 5.6 Take it easy --- see who's talking: take the Turning quiz
- C语言 -- 操作符详解
- 谷粒商城-基础篇(项目简介&项目搭建)
- Handling List
- [One step in place] Jenkins installation, deployment, startup (complete tutorial)
猜你喜欢
符号表
嵌入式系统驱动初级【4】——字符设备驱动基础下_并发控制
day13--postman interface test
Unity自动生成阻挡Collider的GameObject工具
DP4398:国产兼容替代CS4398立体声24位/192kHz音频解码芯片
Web Basics and Exercises for C1 Certification - My Study Notes
7.15 Day21---MySQL----索引
4.3 基于注解的声明式事务和基于XML的声明式事务
Teenage Achievement Hackers Need These Skills
心余力绌:企业面临的软件供应链安全困境
随机推荐
如何低成本修bug?测试左移给你答案
部署LVS-DR群集【实验】
【问题解决】同一机器上Flask部署TensorRT报错记录
Redis common interview questions
Programming hodgepodge (4)
As soon as flink cdc is started, the CPU of the source Oracle server soars to more than 80%. What is the reason?
CentOS7 —— yum安装mysql
The idea setting recognizes the .sql file type and other file types
EntityComponentSystemSamples学习笔记
4.2 Declarative Transaction Concept
The Road to Ad Monetization for Uni-app Mini Program Apps: Full Screen Video Ads
数的划分之动态规划
Handling List
MySQL database (basic)
LCP 17. Quick Calculation Robot
解决安装nbextensions后使用Jupyter Notebook时出现template_paths相关错误的问题
Unity动画生成工具
字节最爱问的智力题,你会几道?
7.18 Day23----标记语言
Write golang simple C2 remote control based on gRPC