手机版

用简单超过导出xls实现方法

时间:2021-10-06 来源:互联网 编辑:宝哥软件园 浏览:

因为前几天写了篇文章,用php-excel阅读器类导入超过内容,顺便说些超过导出问题,我用的是简单的excel,一个很简单的导出xls类,特好用!简单超过源码如下:复制代码代码如下:php /** *从PHP5生成简单Excel * * @软件包实用程序* @ http://www.opensource.org/licenses/mit-license.php许可证* @作者奥利弗史瓦兹[电子邮件保护]* @ 1.0版*/class Excel _ XMl { private $ header='?可扩展标记语言版本=\'1.0 '编码=\'%s\ '?\ \ nWorkbook xmlns=\ ' urn :架构-Microsoft-com : office : pread sheet ' xmlns : x=\ ' urn :架构-Microsoft-com : office : excel ' xmlns :s=\ ' urn :架构-Microsoft-com : office 3: pread sheet ' xmlns : html=\ ' 333333:私有$ footer='/Workbook ';private $ line=array();private $ sencoding private $ bconvertypesprivate $ sWorksheetTitle公共函数__construct($sEncoding='UTF-8 ',$ bConvertTypes=false,$ sWorksheetTitle=' table 1 '){ $ this-bconvertypes=$ bconvertypes;$ this-setEncoding($ sEncoding);$ this-setWorksheetTitle($ Sworksheettitle);}公共函数setEncoding($ sEncoding){ $ this-sEncoding=$ sEncoding;}公共函数setworksheetittle($ title){ $ title=preg _ replace('/[\ \ \ | : | \/| \?|\*|\[|\]]/','',$ title);$title=substr ($title,0,31);$ this-SworkSheetTitle=$ title;}私有函数addRow($ array){ $ cells=' ';foreach($ array as $ k=$ v): $ type=' String ';if($ this-bConvertTypes===true is _ numeric($ v)): $ type=' Number ';endif$v=htmlentities($v,ENT_COMPAT,$ this-sEncoding);$细胞='CellData ss:Type=\'$type\ ' .$ v 。/数据/单元格\ n ';endforeach$ this-line[]=' Row \ n ' .$细胞/Row \ n ';}公共函数addArray($ array){ foreach($ array as $ k=$ v)$ this-addRow($ v);} public function generatexml($ filename=' excel-export '){ $ filename=preg_replace('/[^aa-zz0-9\_\-]/' ' ',$ filename);标题('内容-类型:应用程序/vnd。ms-excel;字符集=' .$ this-sEncoding);标题('内容-处置:内联;文件名=\ ' '。$ filename . xls \ ' ');echo strip斜杠(sprintf($ this-header,$ this-sEncoding));回声\ n工作表ss:Name=\ ' .$this-sWorksheetTitle '\ ' \表\ n ';foreach($本行为$ line)回显$ line回显'/表格\ n/工作表\ n ';echo $ this-footer;} } ?使用服务器端编程语言(专业超文本预处理器的缩写)案例如下: 复制代码代码如下:PHP/* * * @作者麦基* @博客www.phpddt.com */require _ once ' excel。上课。PHP ';$xls=新Excel_Xml('UTF-8 ',false '测试');$data=array(1=array('名称','地址),2=数组(' php点点通,' www.phpddt.com '),3=数组('百度,' www。百度。com’);$ xls-addArray($ data);$ xls-generateXML(' name 4 test ');导出结果如下图用Simple  Excel导出xls

版权声明:用简单超过导出xls实现方法是由宝哥软件园云端程序自动收集整理而来。如果本文侵犯了你的权益,请联系本站底部QQ或者邮箱删除。