当前位置:网站首页>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();
}
边栏推荐
猜你喜欢
随机推荐
npm报错Beginning October 4, 2021, all connections to the npm registry - including for package installa
Towards Real-Time Multi-Object Tracking (JDE)
LCP 17. 速算机器人
C Expert Programming Chapter 4 The Shocking Fact: Arrays and pointers are not the same 4.1 Arrays are not pointers
As soon as flink cdc is started, the CPU of the source Oracle server soars to more than 80%. What is the reason?
Unity开发类似Profile那样的数据分析工具
FPGA学习笔记——知识点总结
MySQL日期函数
[Cocos 3.5.2]开启模型合批
Can 't connect to MySQL server on' localhost3306 '(10061) simple solutions
JS basics - forced type conversion (error-prone, self-use)
Wwise入门和实战
The Road to Ad Monetization for Uni-app Mini Program Apps: Full Screen Video Ads
Write golang simple C2 remote control based on gRPC
擎朗智能全国研发创新中心落地光谷:去年曾获2亿美元融资
7. Execution of special SQL
Deploy LVS-DR cluster [experimental]
编程大杂烩(三)
Several ways to heavy
Sublime Text 3 2021.8.3 个人配置