[PHP] php excel操作类 支持多工作簿和自定义样式 →→→→→进入此内容的聊天室

来自 , 2019-06-15, 写在 PHP, 查看 108 次.
URL http://www.code666.cn/view/8a50bae2
  1. <?php
  2. /**
  3.  * @desc excel接口
  4.  * @author mengdejun
  5.  */
  6. interface  IExcel
  7. {
  8.                 //导入excel
  9.                 public function import($fileName,$convert_callback_function=null);
  10.                 //导出excel
  11.                 public function export($fileName="excel");
  12.                 //添加行
  13.                 public function addRow(array $array,$sheet="sheet1");
  14.                 //添加表头
  15.                 public function addHead(array $array,$sheet="sheet1");
  16.                 //添加工作簿
  17.                 public function  addSheet($sheet);
  18.                 //释放资源
  19.                 public function release();
  20. }
  21. ?>
  22.  
  23.  
  24. <?php
  25. include_once ('IExcel.php');
  26. /**
  27.  * @desc php生成excel类函数
  28.  * @author mengdejun
  29.  * @date 20100806
  30.  * @version 1.1.2
  31.  */
  32. class HtmlExcel implements IExcel
  33. {
  34.         private $_line=array();
  35.         private $isHeader=false;
  36.         private $convert=false;
  37.         public function __construct(){}
  38.  
  39.         /**
  40.          * @desc 添加表头信息,注:表头仅可添加一次,若无表头则将内容行的第一行作为表头
  41.          * @param array $array
  42.          * @param unknown_type $sheet
  43.          */
  44.         public function addHead(array $array, $sheet = "sheet1")
  45.         {
  46.                 if(!$this->isHeader)
  47.                         $this->_line[]=$this->getLine($array);
  48.                 $this->isHeader=true;
  49.         }
  50.  
  51.         /**
  52.          * @desc 添加自定义字符转换或过滤函数
  53.          * @param unknown_type $functionName 回调函数名
  54.          */
  55.         public function addConvert($functionName="convert")
  56.         {
  57.                 $this->convert=$functionName;
  58.         }
  59.  
  60.         protected function getLine(array $array,$sheet='sheet1')
  61.         {
  62.                 $_temp="";
  63.                 $_count=sizeof($array);
  64.                 $index=0;
  65.                         foreach($array as $value):
  66.                                 $_temp.=$this->convert($value);
  67.                                         if($index==$_count-1):
  68.                                                 $_temp.="\t\n";
  69.                                         else:
  70.                                                 $_temp.="\t";
  71.                                         endif;
  72.                                 $index++;
  73.                         endforeach;
  74.                 return $_temp;
  75.         }
  76.  
  77.         /**
  78.          * @desc 添加excel行,若没有设置表头则将该数组的第一个元素作为表头
  79.          * @param array $array
  80.          * @param unknown_type $sheet
  81.          */
  82.         public function addRow(array $array, $sheet = "sheet1")
  83.         {
  84.                 $this->_line[]=$this->getLine($array,$sheet);
  85.                 return $this->_line;
  86.         }
  87.  
  88.         /**
  89.          * @desc 嵌套添加excel行,若没有设置表头则将该数组的第一个元素作为表头
  90.          * @param array $array
  91.          * @param unknown_type $sheet
  92.          */
  93.         public function addRows(array $array,$sheet = "sheet1")
  94.         {
  95.                 foreach($array as $value):
  96.                         if(is_array($value)):
  97.                                 $this->addRow($value);
  98.                         else:
  99.                                 $this->addRow($array);
  100.                         endif;
  101.                 endforeach;
  102.         }
  103.  
  104.         /**
  105.          * @desc 添加工作簿,暂不支持V1.0
  106.          * @deprecated
  107.          * @param array $array
  108.          */
  109.         public function addSheet($sheet) {return;}
  110.  
  111.         /**
  112.          * @desc 返回excel表行数
  113.          */
  114.         public function getRows()
  115.         {
  116.                 return sizeof($this->_line);
  117.         }
  118.  
  119.         /**
  120.          * @desc 返回excel内容
  121.          */
  122.         public function getBody()
  123.         {
  124.                 return $this->_line;
  125.         }
  126.  
  127.         /**
  128.          * @desc 导出excel文件
  129.          * @param unknown_type $fileName 导出文件名
  130.          */
  131.         public function export($fileName = "excel")
  132.         {
  133.                 header("Content-Type: application/vnd.ms-excel;");
  134.                 header("Content-Disposition:filename={$fileName}.xls");
  135.                 for($index=0;$index<sizeof($this->_line);$index++):
  136.                         echo $this->_line[$index];
  137.                 endfor;
  138.         }
  139.  
  140.         /**
  141.          * @desc 用户自定义编码转化以及数据筛选函数
  142.          * @param unknown_type $str
  143.          */
  144.         protected function convert($str)
  145.         {
  146.                 if(function_exists($this->convert)):
  147.                         return call_user_func($this->convert,$str);
  148.                 else:
  149.                         return $str;
  150.                 endif;
  151.         }
  152.  
  153.         /**
  154.          * @desc 设置表格内容
  155.          * @param unknown_type $array
  156.          */
  157.         public function setBody($array)
  158.         {
  159.                 $this->_line=$array;
  160.         }
  161.         /**
  162.          * @desc 释放资源
  163.          */
  164.         public function release()
  165.         {
  166.                 unset($this->_line);
  167.         }
  168.         public function import($fileName,$convert_callback_function=null){}
  169. }
  170. ?>
  171.  
  172. <?php
  173. include_once ('IExcel.php');
  174. /**
  175.  * @desc php生成excel类函数 支持导入 导出 多工作薄(数据分卷技术)
  176.  * @filesource XmlExcel.php
  177.  * @author mengdejun
  178.  * @date 20100801
  179.  * @version 1.8.1
  180.  */
  181. if(!defined("CHARSET")):define("CHARSET","UTF-8");endif;
  182. if(!defined("VERSION")):define("VERSION","12.00");endif;
  183. if(!defined("THIS_VERSION")):define("THIS_VERSION","1.8.1");endif;
  184. if(!defined("NULL")):define("NULL",null);endif;
  185. class XmlExcel implements IExcel
  186. {
  187.         private $header = "<?xml version=\"1.0\" encoding=\"%s\"?>\n<Workbook xmlns=\"urn:schemas-microsoft-com:office:spreadsheet\" xmlns:x=\"urn:schemas-microsoft-com:office:excel\" xmlns:ss=\"urn:schemas-microsoft-com:office:spreadsheet\" xmlns:html=\"http://www.w3.org/TR/REC-html40\">";
  188.         private $documentInfo="<DocumentProperties xmlns=\"urn:schemas-microsoft-com:office:office\"><Author>{author}</Author><Created>{time}</Created><Company>{company}</Company><Version>{version}</Version></DocumentProperties>";
  189.     private $footer = "</Workbook>";
  190.     private $align_left="<Style ss:ID=\"s62\"><Alignment ss:Horizontal=\"Left\" ss:Vertical=\"Center\"/></Style>";
  191.     private $align_center="<Style ss:ID=\"s63\"><Alignment ss:Horizontal=\"Center\" ss:Vertical=\"Center\"/></Style>";
  192.     private $align_right="<Style ss:ID=\"s64\"><Alignment ss:Horizontal=\"Right\" ss:Vertical=\"Center\"/></Style>";
  193.     private $align_bold="<Style ss:ID=\"s65\"><Alignment ss:Horizontal=\"Center\" ss:Vertical=\"Center\"/><Font ss:FontName=\"宋体\" x:CharSet=\"134\" ss:Size=\"12\" ss:Color=\"#000000\" ss:Bold=\"1\"/></Style>";
  194.     private $align_default="<Style ss:ID=\"Default\" ss:Name=\"Normal\"><Alignment ss:Horizontal=\"%s\" ss:Vertical=\"Center\"/><Borders/><Font ss:FontName=\"宋体\" x:CharSet=\"134\" ss:Size=\"11\" ss:Color=\"#000000\"/><Interior/><NumberFormat/><Protection/></Style>";
  195.     private $charset=CHARSET;
  196.     private $convert="convert";
  197.     private static $pre_workBook=NULL;
  198.     private $_line=NULL;
  199.     private $_column=NULL;
  200.     private $_columnType=NULL;
  201.     private $_styles=NULL;
  202.     private $_style=NULL;
  203.     private $_title=NULL;
  204.     private $_align="Left";
  205.     private $defaultHeight=13.5;
  206.     private $defaultWidth=54;
  207.     private $_sheets=NULL;
  208.         private $_heads=NULL;
  209.         /**
  210.          * @desc 构造方法 PHP5.X
  211.          * @param string $charset 字符编码
  212.          */
  213.     public function __construct($charset = 'UTF-8')
  214.     {
  215.         $this->charset=$charset;
  216.     }
  217.     /**
  218.          * @desc 构造方法 PHP4.X
  219.          * @param string $charset 字符编码
  220.          */
  221.     public function XmlExcel($charset = 'UTF-8')
  222.     {
  223.         $this->charset=$charset;
  224.     }
  225.     /**
  226.      * @desc 析构方法
  227.      */
  228.         public function __destruct(){}
  229.         /**
  230.          * @desc 释放可用资源
  231.          * @return null
  232.          */
  233.         public function release()
  234.         {
  235.                 unset($this->_line,$this->_column,$this->_heads,$this->_sheets,$this->_styles,$this->_style,$this->_title,self::$pre_workBook);
  236.         }
  237.     /**
  238.      * @desc 数组行转换函数
  239.      * @param array $array
  240.      */
  241.         protected function getLine(array $array)
  242.         {
  243.                 $_temp="<Row ss:AutoFitHeight=\"0\">";
  244.                         foreach($array as $key=>$val):
  245.                                 #读取指定数据类型,默认String
  246.                                 $_type=!empty($this->_columnType)&&isset($this->_columnType)?!empty($this->_columnType[$key])&&isset($this->_columnType)?$this->_columnType[$key]:"String":"String";
  247.                                 $_temp.="<Cell><Data ss:Type=\"{$_type}\">{$this->convert($val)}</Data></Cell>";
  248.                         endforeach;
  249.                 $_temp.="</Row>";
  250.                 return $_temp;
  251.         }
  252.         /**
  253.          * @desc 添加表格头,默认的第一个数组将作为表头
  254.          * @param array $array
  255.          * @param string $sheet 工作表名
  256.          * @exception $array 不能为空
  257.          */
  258.         public function addHead(array $array, $sheet = "sheet1")
  259.         {
  260.                 $this->_line[$sheet][0]=$this->getLine($array);
  261.                 $this->_title[$sheet]['width']=count($array)-1;
  262.                 $this->_sheets[]=$sheet;
  263.                 $this->_heads[$sheet][0]=$array;
  264.         }
  265.         /**
  266.          * @desc 添加行
  267.          * @param array $array
  268.          * @param string $sheet
  269.          */
  270.         public function addRow(array $array, $sheet = "sheet1",$isErrorReport=true)
  271.         {
  272.                 if($isErrorReport):
  273.                         if(empty($array)||!isset($array)||count($array)==0):
  274.                                 exit("data can't null'");
  275.                         else:
  276.                                 $this->_line[$sheet][]=$this->getLine($array);
  277.                         endif;
  278.                 else:
  279.                         $this->_line[$sheet][]=$this->getLine($array);
  280.                 endif;
  281.         }
  282.         /**
  283.          * @desc 设置工作簿的表头对象
  284.          * @param $head 表头数据
  285.          * @param $sheet 工作簿名称
  286.          */
  287.         public function setSheetHead(array $head,$sheet="Sheet1")
  288.         {
  289.                 $this->_line[$sheet][]=$this->getLine($head);
  290.         }
  291.         /**
  292.          * @desc 添加多行 支持嵌套数组
  293.          * @param array $array
  294.          * @param unknown_type $sheet
  295.          */
  296.         public function addRows(array $array,$sheet = "Sheet1")
  297.         {
  298.                 foreach($array as $value):
  299.                         if(is_array($value)):
  300.                                 $this->addRow($value,$sheet);
  301.                         else:
  302.                                 $this->addRow($array,$sheet);
  303.                         endif;
  304.                 endforeach;
  305.         }
  306.         /**
  307.          * @desc 获取制定工作薄的列宽度
  308.          * @param @sheet 工作薄名称
  309.          */
  310.         public function getColumnLength($sheet="Sheet1")
  311.         {
  312.                 return $this->_title[$sheet]['width'];
  313.         }
  314.         /**
  315.          * @desc 添加工作薄
  316.          * @param unknown_type unknown_type $sheet
  317.          */
  318.         public function addSheet($sheet,$array=array())
  319.         {
  320.                 $this->_line[$sheet][]=$array;
  321.         }
  322.         /**
  323.          * @desc 工作薄添加标题
  324.          * @param string $str 标题
  325.          * @param string $sheet 工作薄名
  326.          */
  327.         public function addTitle($str,$sheet="Sheet1")
  328.         {
  329.                 $str=$this->convert($str);
  330.                 $this->_title[$sheet]['title']="<Row ss:AutoFitHeight=\"0\" ss:StyleID=\"s65\"><Cell ss:MergeAcross=\"{num}\"><Data ss:Type=\"String\">{$str}</Data></Cell></Row>";
  331.         }
  332.         /**
  333.          * @desc excel导出
  334.          * @param string $fileName 导出的文件名
  335.          */
  336.         public function export($fileName = "excel",$isConvert=false)
  337.         {
  338.                 if($isConvert):
  339.                         $fileName=$this->getConvertString($fileName);
  340.                 endif;
  341.                 header("Content-Type: application/vnd.ms-excel; charset=" . $this->charset);
  342.         header("Content-Disposition:attachment; filename=\"{$fileName}.xls\"");
  343.         echo stripslashes(sprintf($this->header, $this->charset));
  344.         echo str_replace("{company}","xiao meng online",str_replace("{time}",date("Y-m-dH:i:s",time()),str_replace("{author}","mengdejun",str_replace("{version}",VERSION,$this->documentInfo))));
  345.         echo "<Styles>";
  346.         echo stripslashes(sprintf($this->align_default, $this->_align));
  347.             echo $this->align_left;
  348.             echo $this->align_right;
  349.             echo $this->align_center;
  350.             echo $this->align_bold;
  351.         echo "</Styles>";
  352.         $_hasData=count($this->_line)==0?false:true;
  353.         if($_hasData):
  354.                 #有数据,解析数组对象到excel表格
  355.                 foreach($this->_line as $key=>$value):
  356.                 echo "<Worksheet ss:Name=\"{$this->convert($key)}\"><Table ss:DefaultColumnWidth=\"{$this->defaultWidth}\" ss:DefaultRowHeight=\"{$this->defaultHeight}\">";
  357.                         #列样式和宽度
  358.                         if(isset($this->_column[$key]['style_width'])):
  359.                                 foreach($this->_column[$key]['style_width'] as $s_key=>$s_value):
  360.                                         echo "<Column ss:Index=\"{$s_key}\" ss:AutoFitWidth=\"1\" ss:Width=\"$s_value\"/>";
  361.                                 endforeach;
  362.                         endif;
  363.                         #表格标题
  364.                         if(!empty($this->_title[$key]['title'])):
  365.                                 echo str_replace("{num}",$this->_title[$key]['width'],$this->_title[$key]['title']);
  366.                         endif;
  367.                         #单元格
  368.                         foreach($value as $_v):
  369.                                 echo $_v;
  370.                         endforeach;
  371.                 echo "</Table></Worksheet>";
  372.                 endforeach;
  373.                 #加载标准工作薄(默认三个工作簿)
  374.                 $length=count($this->_line);
  375.                 while($length<3):
  376.                         $length++;
  377.                         echo "<Worksheet ss:Name=\"Sheet{$length}\"><Table></Table></Worksheet>";
  378.                 endwhile;
  379.         else:
  380.                  #无数据,添加默认工作簿和数据支持(错误处理:文件读取失败)
  381.                  for($index=1;$index<=3;$index++):
  382.                         echo "<Worksheet ss:Name=\"Sheet{$index}\"><Table></Table></Worksheet>";
  383.                  endfor;
  384.         endif;
  385.         echo $this->footer;
  386.         }
  387.         /**
  388.          * @desc excel导入函数,注该函数的文件名必须是非中文
  389.          * @param unknown_type $fileName 导入的文件
  390.          * @param unknown_type $convert_callback_function 回调函数 支持编码转换,需返回转换后的字符串
  391.          * @return 三维数组,分别对应 工作薄/行/单元格
  392.          */
  393.         public function import($fileName,$convert_callback_function=null)
  394.         {
  395.                 $xls=simplexml_load_file($fileName);
  396.                 $is_convert=!empty($convert_callback_function)&&function_exists($convert_callback_function);
  397.                 $index=0;
  398.                 $_ra=array();
  399.                 foreach($xls->Worksheet as $worksheet):#循环工作薄
  400.                         $index_i=1;
  401.                         foreach($worksheet->Table->Row as $cells):#循环行
  402.                                 if($index_i!==1):
  403.                                         foreach($cells as $cell):#循环单元格
  404.                                                 $_ra[$index][$index_i][]=$is_convert?call_user_func($convert_callback_function,$cell->Data):$cell->Data;
  405.                                         endforeach;
  406.                                 endif;
  407.                                 $index_i++;
  408.                         endforeach;
  409.                         $index++;
  410.                 endforeach;
  411.                 return $_ra;
  412.         }
  413.         /**
  414.          * @desc 设置字符编码
  415.          * @param string $charset 设置导出文件的编码
  416.          */
  417.         public function setCharset($charset="GBK")
  418.         {
  419.                 $this->charset = $charset;
  420.         }
  421.  
  422.         /**
  423.          * 设置工作薄的列的宽度 array(1=>10,2=>23,3=>23,4=>213,5=>asd) 重复设置该值 将覆盖前一次操作的结果
  424.          * @param string $sheet 工作薄名
  425.          * @param array $array 列数组
  426.          */
  427.         public function setColumnWidth($sheet="sheet1",$array)
  428.         {
  429.                 if(!empty($this->_column[$sheet]['style_width'])&&isset($this->_column[$sheet]['style_width'])):
  430.                         unset($this->_column[$sheet]['style_width']);
  431.                 endif;
  432.                 $this->_column[$sheet]['style_width']=$array;
  433.         }
  434.         /**
  435.          * @desc 设置所有工作薄的列宽度
  436.          * @param array $array 列宽度
  437.          */
  438.         public function setAllColumnWidth(array $array)
  439.         {
  440.                 $_temp=$this->getAllSheetNames();
  441.                 foreach($_temp as $value):
  442.                         $this->setColumnWidth($value,$array);
  443.                 endforeach;
  444.         }
  445.         /**
  446.          * @desc 设置默认行高
  447.          * @param integer $height
  448.          */
  449.         public function setDefaultRowHeight($height="54")
  450.         {
  451.                 $this->defaultHeight=$height;
  452.         }
  453.         /**
  454.          * 设置字符编码转换函数(回调函数)
  455.          * @param string $convert 设置转换函数 默认名称为convert
  456.          */
  457.         public function addConvert($convert="convert")
  458.         {
  459.                 $this->convert = $convert;
  460.         }
  461.         /**
  462.          * @desc 内部回调函数,完成字符编码的转化
  463.          * @param unknown_type $str
  464.          */
  465.         protected function convert($str)
  466.         {
  467.                 if(function_exists($this->convert)):
  468.                         return call_user_func($this->convert,$str);
  469.                 else:
  470.                         return $str;
  471.                 endif;
  472.         }
  473.         /**
  474.          * 获取工作薄个数
  475.          * @param int $sheet 获取工作薄的个数
  476.          * @return integer
  477.          */
  478.         public function getSheets()
  479.         {
  480.                 return sizeof($this->_line);
  481.         }
  482.         /**
  483.          * 获取工作薄表格行数
  484.          * @param String $sheet 工作薄名
  485.          * @return integer
  486.          */
  487.         public function getRows($sheet)
  488.         {
  489.                 return sizeof($this->_line[$sheet]);
  490.         }
  491.         /**
  492.          * @desc 获取指定工作薄的表头信息
  493.          * @param string $sheet 工作薄名称
  494.          */
  495.         public function getHead($sheet)
  496.         {
  497.                 return $this->_heads[$sheet][0];
  498.         }
  499.         /**
  500.          * @desc 设置默认行高度
  501.          * @param integer $defaultHeight 行的默认高度 无默认值
  502.          */
  503.         public function setDefaultHeight($defaultHeight) {
  504.                 $this->defaultHeight = $defaultHeight;
  505.         }
  506.         /**
  507.          * @desc 设置默认的列宽度
  508.          * @param integer $defaultWidth 列的默认宽度 无默认值
  509.          */
  510.         public function setDefaultWidth($defaultWidth) {
  511.                 $this->defaultWidth = $defaultWidth;
  512.         }
  513.         /**
  514.          * @desc 当前工作薄可用行数
  515.          */
  516.         public function currentSheetsLength()
  517.         {
  518.                 return sizeof($this->_line)+1;
  519.         }
  520.         /**
  521.          * @desc 设置默认的居中方式
  522.          * @param string $_align 可选值 Left(left),Center(center),Right(right)
  523.          */
  524.         public function setDefaultAlign($_align)
  525.         {
  526.                 $this->_align = ucfirst($_align);
  527.         }
  528.         /**
  529.          * @desc 自动创建工作薄,支持自动分卷技术,该方法与addHead冲突,使用该方法时请勿调用addHead,否则将添加一个空白的工作薄
  530.          * @param array $head 表头
  531.          * @param array $data 数据
  532.          * @param int $pageSize 页面行数 默认60000,excel最大支持65536
  533.          * @param string $defaultName 工作薄名,工作簿不能重名
  534.          */
  535.         public function addPageRow(array $head,array $data,$pageSize=60000,$defaultName="Sheet")
  536.         {
  537.                 if(!isset($defaultName)||$defaultName=="Sheet")$defaultName="Sheet".($this->getSheets()+1);
  538.                 if(empty(self::$pre_workBook)):
  539.                         self::$pre_workBook=$defaultName;
  540.                         if(!isset($this->_heads[self::$pre_workBook][0]))
  541.                         $this->addHead($head,self::$pre_workBook);
  542.                         $this->addRow($data,self::$pre_workBook);
  543.                 else:
  544.                         if($this->getRows(self::$pre_workBook)>=($pageSize+1)):
  545.                                 $this->addHead($head,$defaultName);
  546.                                 $this->addRow($data,$defaultName);
  547.                                 self::$pre_workBook=$defaultName;
  548.                         else:
  549.                                 $this->addRow($data,self::$pre_workBook);
  550.                         endif;
  551.                 endif;
  552.         }
  553.         /**
  554.          * @desc 返回所有工作薄名
  555.          * @param null
  556.          */
  557.         public function getAllSheetNames()
  558.         {
  559.                 return $this->_sheets;
  560.         }
  561.         /**
  562.          * @desc 设置所有表格标题(分卷) 默认为合并当前工作薄的所有列,并居中显示(粗体) 该方法必须在工作簿存在的情况下调用.
  563.          * @param string $title 标题
  564.          */
  565.         public function setAllTitle($title)
  566.         {
  567.                 $_temp=$this->getAllSheetNames();
  568.                 foreach($_temp as $value):
  569.                         $this->addTitle($title,$value);
  570.                 endforeach;
  571.         }
  572.         /**
  573.          * @desc 编码转换函数
  574.          * @param string $str 转换的字符串
  575.          * @param string $source_code 原编码 默认UTF-8
  576.          * @param string $target_code 目标编码 默认GBK
  577.          */
  578.         protected function getConvertString($str,$source_code='UTF-8',$target_code='GBK')
  579.         {
  580.                 return !empty($str)&&is_string($str)?iconv($source_code,$target_code,$str):$str;
  581.         }
  582.         /**
  583.          * @desc 打印调试信息
  584.          * @param null
  585.          */
  586.         public function debug($out=true)
  587.         {
  588.                 if($out):
  589.                         var_dump($this->_line);
  590.                 else:
  591.                         return $this->_line;
  592.                 endif;
  593.         }
  594.         /**
  595.          * @desc 工作薄命名后缀 调用此方法将生成全局唯一工作薄名
  596.          * @param $name 自定义工作薄名
  597.          */
  598.         public function uniqueName($name)
  599.         {
  600.                 $size=$this->getSheets();
  601.                 if($size==0)return $name;
  602.                 else return $name.$size;
  603.         }
  604.         /**设置单位格数据类型,该方法需在填充数据前完成 数据类型参照指定版本的excel
  605.          * @param $_columnType the $_columnType to set array 指定的键值对数组
  606.          */
  607.         public function set_columnType($_columnType)
  608.         {
  609.                 $this->_columnType = $_columnType;
  610.         }
  611. }
  612. ?>
  613.  
  614.  
  615. <?php
  616.         include'lib/XmlExcel.php';
  617.         $xls=new XmlExcel;
  618.         $xls->setDefaultWidth(80);
  619.         $xls->setDefaultAlign("center");
  620.         $xls->setDefaultHeight(18);
  621.         $xls->addHead(array("title1","title2","title3","title4","title5","title6"),"demo1");
  622.         for($ind=0;$ind<10;$ind++):
  623.                 $xls->addRow(array($ind,$ind,$ind,$ind,$ind,$ind),"demo1");
  624.         endfor;
  625.         $xls->export("demo1");
  626. ?>
  627.  
  628. <?php
  629.         include'lib/XmlExcel.php';
  630.         $xls=new XmlExcel;
  631.         $xls->setDefaultWidth(80);
  632.         $xls->setDefaultAlign("center");
  633.         $xls->setDefaultHeight(18);
  634.         for($ind=0;$ind<50;$ind++):
  635.                 $xls->addPageRow(array("title1","title2","title3","title4","title5","title6"),array($ind,$ind,$ind,$ind,$ind,$ind),10,$xls->uniqueName("demo"));
  636.         endfor;
  637.         $xls->export("demo2");
  638. ?>

回复 "php excel操作类 支持多工作簿和自定义样式"

这儿你可以回复上面这条便签

captcha