时间:2021-07-01 10:21:17 帮助过:1人阅读
excel2007里面的文档目录组成部分为:
2.我们使用ZipArchive()方法来生成一个简易的excel文件。
使用方法:
3.代码如下:
<?php header("content-type:text/html;charset=utf-8"); //生成一个2007版本的excel文件 //1.实例化一个压缩文档对象 $ex= new ZipArchive(); //2.打开一个excel文件(2007版本) $ex->open('./01.xlsx',ZIPARCHIVE::CREATE); //3.创建excel文档的各个组成文件(文件目录、xml文件) $ex->addFromString('[Content_Types].xml',"<?xml version='1.0' charset='utf-8' ?>"); $ex->addFromString('_rels/.rels',"<?xml version='1.0' charset='utf-8' ?>"); $ex->addFromString('docProps/app.xml',"<?xml version='1.0' charset='utf-8' ?>"); $ex->addFromString('docProps/core.xml',"<?xml version='1.0' charset='utf-8' ?>"); $ex->addFromString('docProps/custom.xml',"<?xml version='1.0' charset='utf-8' ?>"); $ex->addFromString('xl/_rels/workbork.xml.rels',"<?xml version='1.0' charset='utf-8' ?>"); $ex->addFromString('xl/theme/theme1.xml',"<?xml version='1.0' charset='utf-8' ?>"); $ex->addFromString('xl/theme/worksheets/sheet1.xml',"<?xml version='1.0' charset='utf-8' ?>"); $ex->addFromString('xl/theme/worksheets/sheet2.xml',"<?xml version='1.0' charset='utf-8' ?>"); $ex->addFromString('xl/theme/worksheets/sheet3.xml',"<?xml version='1.0' charset='utf-8' ?>"); $ex->addFromString('xl/styles.xml',"<?xml version='1.0' charset='utf-8' ?>"); $ex->addFromString('xl/workbook.xml',"<?xml version='1.0' charset='utf-8' ?>"); ?>
执行php后会生成一个excel2007文件,把此文件改名压缩后就可以看到生成的文件,但此版本的excel文件并不完整,不能使用,要使用还需要借助excel包来完成大量的数据写入功能。此举只是完成ecxcel文件生成的理解。