当前位置:网站首页>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();
}
边栏推荐
- The difference between px, em, and rem
- (Kettle) pdi-ce-8.2 连接MySQL8.x数据库时驱动问题之终极探讨及解决方法分析
- 9. Dynamic SQL
- 力扣:509. 斐波那契数
- Deploy LVS-DR cluster [experimental]
- MySQL database (basic)
- Plus版SBOM:流水线物料清单PBOM
- el-Select selector bottom fixed
- Unity DOTS学习教程汇总
- warning C4251: “std::vector&lt;_Ty&gt;”需要有 dll 接口由 class“Test”的客户端使用错误
猜你喜欢
![[Cloud Native--Kubernetes] Pod Resource Management and Probe Detection](/img/1a/b3bdf9b62c82b0fc4d913045981d94.png)
[Cloud Native--Kubernetes] Pod Resource Management and Probe Detection

触觉智能分享-SSD20X实现升级显示进度条

【论文阅读笔记】无监督行人重识别中的采样策略

8.03 Day34---BaseMapper query statement usage

编程大杂烩(四)

The cost of automated testing is high and the effect is poor, so what is the significance of automated testing?

想低成本保障软件安全?5大安全任务值得考虑

Unity动画生成工具

About yolo7 and gpu

部署LVS-DR群集【实验】
随机推荐
Get the selected content of the radio box
TensorRT例程解读之语义分割demo
8大软件供应链攻击事件概述
动态规划总括
MySQL数据库面试题总结(2022最新版)
Embedded system driver primary [3] - _IO model in character device driver foundation
About yolo7 and gpu
力扣:509. 斐波那契数
Cannot read properties of null (reading ‘insertBefore‘)
编程大杂烩(四)
力扣:63. 不同路径 II
Gartner 权威预测未来4年网络安全的8大发展趋势
npm init [email protected] 构建项目报错SyntaxError: Unexpected token ‘.‘解决办法
MySQL log articles, binlog log of MySQL log, detailed explanation of binlog log
4.2 声明式事务概念
4.1 JdbcTemplate for declarative transactions
Plus版SBOM:流水线物料清单PBOM
The symbol table
读者让我总结一波 redis 面试题,现在肝出来了
MySQL database (basic)