Using the PHPExcel library
/** * excel 写入,基于PHPExcel库 * @param array $data * @param $file * @return bool * @throws PHPExcel_Exception * */ function excel_insert(array $data,$file){ // $data = [ // '库房'=>[ // ['库房编号','库房名词',1], // ['库房编号','库房名词',1], // ['库房编号','库房名词',1], // ['库房编号','库房名词',1], // ['库房编号','库房名词',1], // ], // '库房2'=>[ // ['库房编号','库房名词',1], // ['库房编号','库房名词',1], // ['库房编号','库房名词',1], // ['库房编号','库房名词',1], // ['库房编号','库房名词',1], // ], // ]; // excel_insert($data,'s.xlsx'); if(!$data||!$file){ return false; } $sheet_id = 0; //创建excel操作对象 $objPHPExcel = new PHPExcel(); //获得文件属性对象,给下文提供设置资源 $objPHPExcel->getProperties()->setCreator("绵阳市碳素云信息技术有限责任公司") ->setLastModifiedBy("绵阳市碳素云信息技术有限责任公司") ->setTitle("Input_Goods_message") ->setSubject("主题1") ->setDescription("随便一个描述了") ->setKeywords("关键字 用空格分开") ->setCategory("分类 "); for($i=1;$i<count($data);$i++){ $objPHPExcel->addSheet(new PHPExcel_Worksheet($objPHPExcel,'sheet'.$i)); } foreach($data as $sheetName => $sheetData){ $Sheet = $objPHPExcel->setActiveSheetIndex($sheet_id); $Sheet->setTitle($sheetName); $insert_id = 1; foreach($sheetData as $rowData){ if(is_array($rowData)&&$rowData){ foreach($rowData as $id => $cellData){ if(is_numeric($id)&&(is_string($cellData)||is_numeric($cellData))){ $Sheet->setCellValue(chr(65+$id).$insert_id,$cellData); }else{ return false; } } $insert_id++; }else{ return false; } } $sheet_id++; } try{ $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); $objWriter->save($file); }catch (Exception $e){ return false; } }
Copy after login
How to use:
$data = [ '库房'=>[ ['库房编号','库房名词',1], ['库房编号','库房名词',1], ['库房编号','库房名词',1], ['库房编号','库房名词',1], ['库房编号','库房名词',1], ], '库房2'=>[ ['库房编号','库房名词',1], ['库房编号','库房名词',1], ['库房编号','库房名词',1], ['库房编号','库房名词',1], ['库房编号','库房名词',1], ], ]; excel_insert($data,'s.xlsx');
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article
What's New in Windows 11 KB5054979 & How to Fix Update Issues
3 weeks ago
By DDD
How to fix KB5055523 fails to install in Windows 11?
2 weeks ago
By DDD
InZoi: How To Apply To School And University
3 weeks ago
By DDD
How to fix KB5055518 fails to install in Windows 10?
2 weeks ago
By DDD
Roblox: Dead Rails – How To Summon And Defeat Nikola Tesla
4 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)
