思路话语

。Arlen:思想有多远你就能走多远...

分页取数存入数组的一段示例代码

代码
1.private function _get_content_list()   
2.   {   
3.       $temp_content_list ;   
4.          
5.       $ExpandedRowCount = 1;   
6.       if(!is_null($this->excel_content) && is_array($this->excel_content))   
7.       {   
8.           $cell_keys = array_keys($this->excel_header);   
9.                          
10.           $total_rows = count($this->excel_content);   
11.                                      
12.           $temp_content = '';   
13.           $page_index = 1;   
14.           for($i = 0$i < $total_rows$i ++)   
15.           {   
16.               //拼$temp_content   
17.               $content_item = $this->excel_content[$i];   
18.               //关键点1   
19.               if(!is_null($content_item&& is_array($content_item))   
20.               {   
21.                   $temp_content .= "<Row>";   
22.                   foreach($cell_keys as $cell_name)   
23.                   {   
24.                       if(isset($content_item[$cell_name]))   
25.                       {   
26.                           $temp_content .= '<Cell><Data ss:Type="String">' . $this->_trans_xml_char($content_item[$cell_name]) . '</Data></Cell>';   
27.                       }   
28.                   }   
29.                   $temp_content .= "</Row>";   
30.                   $ExpandedRowCount ++;   
31.               }     
32.               //关键点2                      
33.               if($page_index * Excel::ROWS_WORK_SHEET == ($i + 1))                   
34.               {                                      
35.                   $temp_content_list[] = array("content"=>$temp_content, "expandedRowCount"=>$ExpandedRowCount);   
36.                   $temp_content = '';   
37.                   $ExpandedRowCount = 1;   
38.                   $page_index ++;   
39.               }                   
40.           }   
41.              
42.           //关键点3   
43.           if($total_rows % Excel::ROWS_WORK_SHEET > 0)   
44.              $temp_content_list[] = array("content"=>$temp_content, "expandedRowCount"=>$ExpandedRowCount);     
45.       }   
46.                  
47.       return $temp_content_list;   
48.   }

 

posted on 2010-03-23 13:50  Arlen  阅读(152)  评论(0)    收藏  举报

导航