/** * 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; } }
How to use:
$data = [ '库房'=>[ ['库房编号','库房名词',1], ['库房编号','库房名词',1], ['库房编号','库房名词',1], ['库房编号','库房名词',1], ['库房编号','库房名词',1], ], '库房2'=>[ ['库房编号','库房名词',1], ['库房编号','库房名词',1], ['库房编号','库房名词',1], ['库房编号','库房名词',1], ['库房编号','库房名词',1], ], ]; excel_insert($data,'s.xlsx');

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

Hot Tools

Dreamweaver Mac version
Visual web development tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download
The most popular open source editor

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.
