1.åºäºphpä¸ä½¿ç¨excelçç®åä»ç»
2.php生成excel完整实例代码
3.php无法导出excel的源码问题 跪求高人指点。
åºäºphpä¸ä½¿ç¨excelçç®åä»ç»
å¨å·¥ä½ä¸éè¦å¤çå¤è¯è¨çç¿»è¯é®é¢ï¼ç¿»è¯é½æ¯åå¨excelè¡¨æ ¼éé¢ã为äºå¤çæ¹ä¾¿æå°±ä¿çä¸æåè±æ两åãè¿æ ·éè¦å°è¿äºæ°æ®ä»excelä¸ååºæ¥ï¼ç¶ä¹ä¿åå¨excelçæ°ç»ä¸ï¼éè¿ä½¿ç¨å¾ªç¯æ°ç»å°ç¸åºçæ°æ®æ¾å ¥å°æ°æ®åºä¸ã
æ以工ä½ç第ä¸æ¥å°±æ¯è¦å°æ°æ®ä»excelä¸ååºæ¥ãè¿éæ使ç¨å°äºä¸ä¸ªå¼æºphpå¤çexcelç±»ï¼phpexcel.
该项ç®ç详ç»ä¿¡æ¯
/
ã
æç®å使ç¨çæ¯phpexcel1.7.3çæ¬,源码蓝牙 歌曲源码音频
解å缩åéé¢æä¸ä¸ªPHPExcelåPHPExcel.phpæ件ã
æ们主è¦ä½¿ç¨é£ä¸ªPHPæ件ãè§ä¸å¾æ件ç®å½ç»æ
è¿ä¸ªçæ¬æ®è¯´æ¯å¯ä»¥æ¯æexcelï¼ä½æ¯æ使ç¨ç¼è¾çxlsxæ¯æ æ³è·å¾è¯¥åºçæ¯æãäºæ¯ä¹æå°±å°å®è½¬å为ãæè§æ¯æå°å¾å¥½ã
ä¸é¢ä»ç»ä¸ä¸å ·ä½ç使ç¨ï¼
å¤å¶ä»£ç
代ç å¦ä¸:
require_once('./phpexcel1.7.3/PHPExcel.php');
$php_excel_obj
=
new
PHPExcel();
$php_reader
=
newPHPExcel_Reader_Excel();
if(!$php_reader->canRead($file_name)){
$php_reader=
new
PHPExcel_Reader_Excel5();
if(!$php_reader->canRead($file_name)){
echo'NO
Excel!';
}
}
$php_excel_obj
=
$php_reader->load($file_name);
$current_sheet
=$php_excel_obj->getSheet(0);
ä¸é¢ç主è¦åè½æ¯åå§åç¸å ³çexcelç±»ï¼å¹¶è£ è½½excel第ä¸ä¸ªsheet
å¤å¶ä»£ç
代ç å¦ä¸:
$all_column
=$current_sheet->getHighestColumn();
$all_row
=$current_sheet->getHighestRow();
以ä¸åå«è·å¾è¯¥è¡¨æ ¼çæ大åå¼(åæ¯è¡¨ç¤ºå¦ï¼âG'),åæ大çè¡æ°ï¼æ°å¼è¡¨ç¤ºï¼
ä¸é¢å°ä½¿ç¨å¾ªç¯æ¥è®²exceléé¢çæ°æ®è¯»å°excelä¸ï¼
å¤å¶ä»£ç
代ç å¦ä¸:
$all_arr
=
array();
$c_arr
=
array();
//åç¬¦å¯¹ç §è¡¨
for($r_i
=
1;
$r_i<=$all_row;
$r_i++){
$c_arr=
array();
for($c_i=
'A';
$c_i<=
'B';
$c_i++){
$adr=
$c_i
.
$r_i;
$value=
$current_sheet->getCell($adr)->getValue();
if($c_i==
'A'
&&
empty($value)
)
break;
if(is_object($value))
$value=
$value->__toString();
$c_arr[$c_i]=
$value;
}
$c_arr&&
$all_arr[]
=
$c_arr;
}
ä¸é¢ç®åå°ä»ç»ä¸ä¸phpexcelçåæä½ï¼è¿ä¸ªæä½ç»å¸¸ç¨äºå°æ°æ®åºä¸çæ°æ®å¯¼å ¥å°excelä¸ï¼ä¾¿äºå±ç¤ºååææ´ç¾è§çææã
å¤å¶ä»£ç
代ç å¦ä¸:
require_once('./phpexcel1.7.3/PHPExcel.php');
$excel_obj
=
new
PHPExcel();
$objWriter
=
newPHPExcel_Writer_Excel5($excel_obj);
$excel_obj->setActiveSheetIndex(0);
$act_sheet_obj=$excel_obj->getActiveSheet();
$act_sheet_obj->setTitle('sheet');
$act_sheet_obj->setCellValue('A1',
'å符串å 容');
$act_sheet_obj->setCellValue('A2',
);
$file_name
=
"output.xls";
$objWriter->save($file_name);
代ç å¾ç®åï¼
é¦å åå§åç¸å ³çexcelåç±»ï¼ç¶ååå ¥æ°æ®ï¼æåä¿å为xlsæ件ã
è¾åºçææè§å¾
php生成excel完整实例代码
下载phpexcel类库 代码如下:
<?php
require_once('PHPExcel.php');
require_once('PHPExcel/IOFactory.php');
$objPHPExcel=new PHPExcel();
$iofactory=new IOFactory();
//获得数据 ---一般是从数据库中获得数据
$data=array(
0=>array('id'=>,'name'=>'张某某','age'=>),
1=>array('id'=>,'name'=>'EVA','age'=>)
);
//设置excel列名
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1','编号');
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('B1','姓名');
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('C1','年龄');
//把数据循环写入excel中
foreach($data as $key => $value){
$key+=2;
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('A'.$key,$value['id']);
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('B'.$key,$value['name']);
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('C'.$key,$value['age']);
}
//excel保存在根目录下 如要导出文件,以下改为注释代码
$objPHPExcel->getActiveSheet() -> setTitle('SetExcelName');
$objPHPExcel-> setActiveSheetIndex(0);
$objWriter = $iofactory -> createWriter($objPHPExcel,源码中英源码 'Excel');
$objWriter -> save('SetExcelName.xlsx');
//导出代码
// $objPHPExcel->getActiveSheet() -> setTitle('SetExcelName');
// $objPHPExcel-> setActiveSheetIndex(0);
// $objWriter = $iofactory -> createWriter($objPHPExcel, 'Excel');
// $filename = 'SetExcelName.xlsx';
// header('Content-Type: application/vnd.ms-excel');
// header('Content-Type: application/octet-stream');
// header('Content-Disposition: attachment; filename="' . $filename . '"');
// header('Cache-Control: max-age=0');
// $objWriter -> save('php://output');
>php无法导出excel的问题 跪求高人指点。
<?源码扫雷 源码php
public function excel()
{
//在这里调用你要导出的数据
$data = M('pmproject',"pm_",MYSQL_PSA)->select();
//列名数组
$tableheader = array('ID', '标题', '内容');
ob_end_clean();
Vendor('PHPExcel.PHPExcel');
//创建对象
$excel = new \PHPExcel();
//Excel表格式,这里简略写了8列
$letter = array('A', 'B', 'C', 'D', 'E', 'F', 'F', 'G');
//填充表头信息
for ($i = 0; $i < count($tableheader); $i++)
{
$excel->getActiveSheet()->setCellValue("$letter[$i]1", "$tableheader[$i]");
}
//填充表格信息
for ($i = 2; $i <= count($data) + 1; $i++)
{
$j = 0;
foreach ($data[$i - 2] as $key => $value)
{
$excel->getActiveSheet()->setCellValue("$letter[$j]$i", "$value");
$j++;
}
}
//创建Excel输入对象
$write = new \PHPExcel_Writer_Excel5($excel);
header("Pragma: public");
header("Expires: 0");
header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
header("Content-Type:application/force-download");
header("Content-Type:application/vnd.ms-execl");
header("Content-Type:application/octet-stream");
header("Content-Type:application/download");
header('Content-Disposition:attachment;filename="testdata.xls"');
header("Content-Transfer-Encoding:binary");
$write->save('php://output');
}
>不需要任何插件,调用这个函数,源码tommath 源码直接输出excle表格,源码hackrf源码有问题联系我q
源码源码**