当前位置:网站首页>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();
}
边栏推荐
猜你喜欢
![[Cocos 3.5.2]开启模型合批](/img/d9/9e8f71c9a26c8052b11291fe3ba7ac.png)
[Cocos 3.5.2]开启模型合批

读者让我总结一波 redis 面试题,现在肝出来了

el-Select selector bottom fixed

嵌入式系统驱动初级【3】——字符设备驱动基础中_IO模型
![Deploy LVS-DR cluster [experimental]](/img/ad/84e05a6421d668b0b6ba6eeba0c730.jpg)
Deploy LVS-DR cluster [experimental]

Wwise入门和实战
![Embedded system driver primary [3] - _IO model in character device driver foundation](/img/c7/21fc0651964a6a435e8ec5743b7662.png)
Embedded system driver primary [3] - _IO model in character device driver foundation

在被面试官说了无数次后,终于潜下心来整理了一下JVM的类加载器

Typora 使用保姆级教程 | 看这一篇就够了 | 历史版本已被禁用

Teenage Achievement Hackers Need These Skills
随机推荐
Can‘t connect to MySQL server on ‘localhost3306‘ (10061) 简洁明了的解决方法
力扣:343. 整数拆分
处理List<Map<String, String>>类型
Can 't connect to MySQL server on' localhost3306 '(10061) simple solutions
想好了吗?
How to view sql execution plan offline collection
Typora 使用保姆级教程 | 看这一篇就够了 | 历史版本已被禁用
leetcode 12. Integer to Roman numeral
Embedded system driver primary [4] - under the basis of character device driver _ concurrency control
Redis common interview questions
OpenSSF 安全计划:SBOM 将驱动软件供应链安全
一个对象引用的思考
7.18 Day23----标记语言
Cannot read properties of null (reading ‘insertBefore‘)
心余力绌:企业面临的软件供应链安全困境
Unity动画生成工具
8大软件供应链攻击事件概述
The idea setting recognizes the .sql file type and other file types
7.15 Day21---MySQL----索引
Cannot read properties of null (reading 'insertBefore')